-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfendo.addon.hierarchy_meta_links.fs
217 lines (192 loc) · 6.97 KB
/
fendo.addon.hierarchy_meta_links.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
.( fendo.addon.hierarchy_meta_links.fs) cr
\ This file is part of Fendo
\ (http://programandala.net/en.program.fendo.html).
\ This file is the hierarchy meta links addon.
\ Last modified 20211023T1637+0200.
\ See change log at the end of the file.
\ Copyright (C) 2013,2014,2015,2017,2018,2021 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).
\ ==============================================================
: proper_hierarchical_link? ( ca len -- ca' len' f )
\ ." Stack before `unshortcut` in `proper_hierarchical_link? : " .s cr \ XXX INFORMER
\ ." Parameter of `proper_hierarchical_link? : " 2dup type cr \ XXX INFORMER
\ key drop \ XXX INFORMER
unshortcut
\ ." Stack after `unshortcut` in `proper_hierarchical_link? : " .s cr key drop \ XXX INFORMER
dup
if 2dup pid$>draft?
\ ." Stack after `pid$>draft?` in `proper_hierarchical_link? : " .s cr \ XXX INFORMER
0= else false then
\ ." Stack at the end of `proper_hierarchical_link? : " .s cr \ XXX INFORMER
\ key drop \ XXX INFORMER
;
\ doc{
\
\ proper_hierarchical_link? ( ca len -- ca' len' f )
\
\ If page ID _ca len_ is a proper hierarchical link (i.e., not a
\ draft page), _f_ is true and _ca' len'_ is its equivalent
\ `unshortcut` page ID; otherwise _f_ is false and _ca' len'_ is
\ unimportant.
\
\ This check is required in order to bypass the default behaviour of
\ links: a link to a draft local page simply prints the link text,
\ but that is not convenient for the hierarchy meta links. This
\ check can be used also by the application, as part of the user's
\ hierarchy navigation bar.
\
\ ``proper_hierarchical_link?`` is used by `hierarchical_meta_link`.
\
\ See also: `hierarchical_meta_links`, `pid$>draft?`.
\
\ }doc
: (hierarchy_meta_link) ( ca1 len1 ca2 len2 -- )
\ cr 2dup type ." --> " 2over type \ XXX INFORMER
rel=!
\ ." Pid parameter in `(hierarchy_meta_link)` before `pid$>pid#` = " 2dup type cr \ XXX INFORMER
\ ." `link_anchor` in `(hierarchy_meta_link)` before `pid$>pid#` = " link_anchor $@ type cr \ XXX INFORMER
pid$>pid#
\ ." `href=` in `(hierarchy_meta_link)` after `pid$>pid#` = " href=@ type cr \ XXX INFORMER
\ ." `link_anchor` in `(hierarchy_meta_link)` after `pid$>pid#` = " link_anchor $@ type cr \ XXX INFORMER
dup target_file href=!
dup title unmarkup title=!
?hreflang=! s" text/html" type=!
[<link/>] ;
\ doc{
\
\ (hierarchy_meta_link) ( ca1 len1 ca2 len2 -- )
\
\ Create a hierarchy meta link to page ID _ca2 len2_,
\ with ``rel`` attribute _ca1 len2_.
\
\ ``(hierarchy_meta_link)`` is a factor of `hierarchy_meta_link`.
\
\ See also: `[<link/>]`.
\
\ }doc
: hierarchy_meta_link ( ca1 len1 ca2 len2 -- )
\ ." Stack in `hierarchy_meta_link` : " .s cr \ XXX INFORMER
\ ." Parameter in `hierarchy_meta_link` = " 2dup type cr \ XXX INFORMER
\ key drop \ XXX INFORMER
proper_hierarchical_link?
\ ." Stack in `hierarchy_meta_link` after `proper_hierarchical_link?` : " .s cr \ XXX INFORMER
\ key drop \ XXX INFORMER
if 2swap (hierarchy_meta_link) else 2drop 2drop then ;
\ doc{
\
\ hierarchy_meta_link ( ca1 len1 ca2 len2 -- )
\
\ If needed, create a hierarchy meta link to page ID _ca2 len2_,
\ with ``rel`` attribute _ca1 len2_.
\
\ Usage example in the HTML template:
\ ----
\ <head>
\ <title>Page 1</title>
\ <[
\ s" prev" s" page_0" hierarchy_meta_link
\ s" next" s" page_2" hierarchy_meta_link
\ ]>
\ </head>
\ ----
\ ``hierarchy_meta_link`` is needed only in special cases.
\ `hierarchy_meta_links` can be used instead to create all
\ hierarchical links automatically.
\
\ See also: `(hierarchy_meta_link)`.
\
\ }doc
: hierarchy_meta_links ( -- )
\ s" up" current_page ?upper_page hierarchy_meta_link
s" next" current_page ?next_page hierarchy_meta_link
s" prev" current_page ?previous_page hierarchy_meta_link
\ s" first" current_page ?first_page hierarchy_meta_link
\ s" last" current_page ?last_page hierarchy_meta_link
;
\ XXX TMP 2015-02-26: it seems "up", "first" and "last" are not allowed
\ in <link>; I comment them out.
\ XXX TODO -- Confirm.
\ doc{
\
\ hierarchy_meta_links ( -- )
\
\ Create the hierarchy meta links of the current page.
\
\ NOTE: Only "next" and "prev" are created. "up", "first" and "last"
\ are not allowed in HTML ``<link>`` tag.
\
\ Usage example in the HTML template:
\
\ ----
\ <head>
\ <[ hierarchy_meta_links ]>
\ </head>
\ ----
\
\ See also: `hierarchy_meta_link`.
\
\ }doc
.( fendo.addon.hierarchy_meta_links.fs compiled) cr
\ ==============================================================
\ Change log {{{1
\ 2013-10-14 Moved from the application Fendo-programandala.
\
\ 2013-10-27 Change: `hierarchy_meta_link` simplified.
\
\ 2013-11-26 Change: several words renamed, after a new uniform
\ notation: "pid$" and "pid#" for both types of page IDs.
\
\ 2014-11-08: Change: `unmarkup` (just implemented) is used instead of
\ hard-coded plain text versions of some data fields.
\
\ 2014-11-08: Improved: `hierarchy_meta_link` factored out from
\ `hierarchy_meta_links`; `unshortcut` added.
\
\ 2014-11-08: Fix: `unshortcut` was missing.
\
\ 2014-11-08: Fix: second `2drop` was missing in
\ `hierarchy_meta_link`.
\
\ 2015-01-17: New: `proper_hierarchical_link?`.
\
\ 2015-01-17: Fix: `hierarchy_meta_link` uses the new
\ `proper_hierarchical_link?` and does not create links to local draft
\ pages anymore.
\
\ 2015-02-26: Fix: It seems "up", "first" and "last" are not allowed
\ in <link>; I comment them out in the hierarchical meta links.
\
\ 2015-02-26: Fix: 's" text/html" type=!' was missing in the
\ hierarchical meta links.
\
\ 2017-06-22: Update source style, layout and header.
\
\ 2017-06-25: Factor `proper_hierarchical_link?` to `pid$>draft?`.
\
\ 2018-09-12: Add debugging code to explore the problem detected in
\ `(required_data)` (see change log of <fendo.data.fs>).
\
\ 2018-09-28: Replace `previous_page` with `?previous_page`. Replace
\ `next_page` with `?next_page`.
\
\ 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#`.
\
\ 2018-12-20: Improve documentation.
\
\ 2021-10-23: Replace "See:" with "See also:" in the documentation.
\ vim: filetype=gforth