-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfendo.addon.tag_cloud_by_prefix.fs
221 lines (177 loc) · 6.72 KB
/
fendo.addon.tag_cloud_by_prefix.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
.( fendo.addon.tag_cloud_by_prefix.fs) cr
\ This file is part of Fendo
\ (http://programandala.net/en.program.fendo.html).
\ This file provides tag clouds by a page-id prefix.
\ Last modified 20220123T1353+0100.
\ See change log at the end of the file.
\ Copyright (C) 2014,2017,2018,2020 Marcos Cruz (programandala.net)
\ Fendo is free software; you can redistribute it and/or modify it
\ under the terms of the GNU General Public License as published by
\ the Free Software Foundation; either version 2 of the License, or
\ (at your option) any later version.
\ Fendo is distributed in the hope that it will be useful, but WITHOUT
\ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
\ License for more details.
\ You should have received a copy of the GNU General Public License
\ along with this program; if not, see <http://gnu.org/licenses>.
\ Fendo is written in Forth (http://forth-standard.org)
\ with Gforth (http://gnu.org/software/gforth).
\ ==============================================================
\ Requirements {{{1
forth_definitions
require galope/max-n.fs \ `max-n`
require galope/package.fs \ `package`, `private`, `public`, `end-package`
require galope/rgx-wcmatch-question.fs \ `rgx-wcmatch?`
fendo_definitions
\ require ./fendo.addon.regex.fs \ XXX TODO
require ./fendo.addon.tags.fs
require ./fendo.addon.traverse_pids.fs
require ./fendo.addon.pages_by_prefix.fs
\ require ./fendo.addon.tag_counts_by_prefix.fs \ XXX TODO
\ ==============================================================
\ Code {{{1
package fendo.addon.tag_cloud_by_prefix
variable tag_min_count
variable tag_max_count
variable pages
: (tag_does_min_max) ( tag -- )
tag>count @ dup
tag_min_count @ min tag_min_count !
tag_max_count @ max tag_max_count ! ;
\ Update the min and max count with the count of the given tag.
: tags_do_min_max ( -- )
max-n tag_min_count ! 0 tag_max_count !
['] (tag_does_min_max) is (tag_does) execute_all_tags
\ tag_min_count @ tag_max_count @ \ XXX OLD XXX TMP --
;
: count_tags ( ca len -- )
\ cr ." pid$ = " 2dup type \ XXX INFORMER
pid$>pid# tags
\ cr ." tags = " 2dup type \ XXX INFORMER
evaluate_tags ;
\ Count the tags in the given page ID
\ ca len = page ID
variable prefix$ \ module variable; in <fendo.addon.pages_by_prefix.fs> there's another one
: (count_tags_by_prefix) { D: pid -- }
\ cr ." In count_tags_by_prefix pid is " pid type \ XXX INFORMER
\ ." and prefix is <" prefix$ $@ type ." >" cr \ XXX INFORMER
pid prefix$ $@ string-prefix? 0= ?exit
pid pid$>pid# draft? ?exit
pid count_tags ;
\ Increase the count of tags that are in pages whose page ID
\ matches the current regex.
: count_tags_by_prefix ( ca len -- f )
(count_tags_by_prefix) true ;
\ ca len = page ID
\ f = continue with the next element?
: init_tags ( xt -- min max)
\ ." init_tags" cr \ XXX INFORMER
tags_do_reset execute_all_tags tags_do_increase traverse_pids
tags_do_min_max ;
\ xt = parameter for `traverse_pids`
public
variable tag_cloud_with_counts \ flag
variable tag_cloud_with_sizes \ flag
variable tag_cloud_counts_sized \ flag \ XXX TODO better name
variable tag_min_size \ percentage
variable tag_max_size \ percentage
\ Default config, to be changed by the application:
tag_cloud_with_counts on
tag_cloud_with_sizes on
tag_cloud_counts_sized off
090 tag_min_size !
400 tag_max_size !
private
: (tag_count) ( tag -- )
s\" <span class=\"tagCount\">(" echo
tag>count @
\ dup ." count=" . key drop \ XXX INFORMER
echo.
\ s" /" echo pages @ echo. \ XXX TMP
\ ." pages " pages @ . \ XXX INFORMER
s" )</span>" echo ;
: tag_count ( tag -- )
tag_cloud_with_counts @ if (tag_count) else drop then ;
: tag_size_range ( -- n )
tag_max_size @ tag_min_size @ - ;
: tag_count_range ( -- n )
tag_max_count @ tag_min_count @ - ;
: tag_size ( +n1 -- +n2 )
tag_min_count @ - 100 * tag_count_range /
tag_size_range * 100 / tag_min_size @ + ;
\ +n1 = tag count
\ +n2 = tag size (percentage)
: tag_cloud_sizes ( tag -- )
tag>count @ tag_size n>str s" %" s+ s" font-size:" 2swap s+ style=! ;
\ Set the font size style for the next HTML tag, actually <li> or <a>.
: ?tag_cloud_sizes ( tag f -- )
tag_cloud_with_sizes @ and if tag_cloud_sizes else drop then ;
\ Set the font size style for the next HTML tag, actually <li> or <a>,
\ if needed.
: (tag_does_echo_cloud) { tag -- }
\ tag tag>name cr ." In (tag_does_echo_cloud) the tag name is " type \ XXX INFORMER
tag tag_cloud_counts_sized @ ?tag_cloud_sizes [<li>]
tag tag_cloud_counts_sized @ 0= ?tag_cloud_sizes
tag tag_link tag tag_count [</li>] ;
\ Create a tag cloud link to the given tag.
: tag_does_echo_cloud ( tag -- )
dup tag>count @
\ dup cr ." In tag_does_echo_cloud the tag count is " . \ XXX INFORMER
if (tag_does_echo_cloud) else drop then ;
\ Create a tag cloud link to the given tag, if needed.
: tags_do_echo_cloud ( -- )
['] tag_does_echo_cloud is (tag_does) ;
: do_tag_cloud ( xt -- )
\ ." do_tag_cloud " cr \ XXX INFORMER
init_tags
\ ." do_tag_cloud after init_tags" cr \ XXX INFORMER
[<ul>] tags_do_echo_cloud execute_all_tags [</ul>]
\ ." do_tag_cloud end" cr \ XXX INFORMER
;
\ xt = parameter for `init_tags`
public
: tag_cloud_by_prefix ( ca len -- )
\ cr ." In tag_cloud_by_prefix the prefix is " 2dup type key drop \ XXX INFORMER
2dup prefix$ $! pages_by_prefix drop
['] count_tags_by_prefix do_tag_cloud ;
\ Create a tag cloud
\ with pages whose page ID matches the given prefix.
end-package
.( fendo.addon.tag_cloud_by_prefix.fs compiled) cr
\ ==============================================================
\ Change log {{{1
\ 2014-03-03: Start.
\
\ 2014-03-07: First working version.
\
\ 2014-03-08: Improved. First draft to change the size of tags.
\
\ 2014-03-09: Fix: calculation for the tag font size.
\
\ 2014-03-12: Improvement: faster, with additional `?exit` and rearranged
\ conditions.
\
\ 2014-05-28: Change: `++` used.
\
\ 2014-05-28: New: `tags_used_only_once_link_to_its_own_page` flag.
\
\ 2014-06-03: Change: `tags_used_only_once_link_to_its_own_page`
\ renamed to `lonely_tags_link_to_content`.
\
\ 2014-10-12: Fix: now `tag_cloud_by_prefix` also sets the `prefix$`
\ variable, because `pages_by_prefix` sets a homonymous module variable.
\
\ 2017-06-22: Update source style, layout and header.
\
\ 2018-09-27: Use `package` instead of `module:`.
\
\ 2018-12-08: Update notation of Forth words in comments and strings.
\
\ 2018-12-08: Update notation of page IDs in comments and strings.
\
\ 2018-12-17: Update: replace `pid$>data>pid#` with `pid$>pid#`.
\
\ 2020-04-21: Update: `lonely_tags_link_to_content` was removed in
\ <fendo.addon.tags.fs>.
\ vim: filetype=gforth