-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfendo.addon.sitemap.xml.fs
292 lines (229 loc) · 8.44 KB
/
fendo.addon.sitemap.xml.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
.( fendo.addon.sitemap.xml.fs) cr
\ This file is part of Fendo
\ (http://programandala.net/en.program.fendo.html).
\ This file is the Sitemap.xml addon.
\ XXX UNDER DEVELOPMENT
\ Last modified 202011160218.
\ See change log at the end of the file.
\ Copyright (C) 2015,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).
\ ==============================================================
\ TODO {{{1
\ Everything.
\ ==============================================================
\ Requirements {{{1
forth_definitions
require galope/n-to-r.fs \ `n>r`
require galope/n-r-from.fs \ `nr>`
require galope/s-constant.fs \ `sconstant`
fendo_definitions
\ ==============================================================
\ Configurable texts {{{1
s" Content"
sconstant sitemap_default_content$
defer sitemap_content$
' sitemap_default_content$ is sitemap_content$
s" <strong>New page<strong>: "
sconstant sitemap_default_new_page$
defer sitemap_new_page$
' sitemap_default_new_page$ is sitemap_new_page$
s" <strong>Updated page</strong>: "
sconstant sitemap_default_updated_page$
defer sitemap_updated_page$
' sitemap_default_updated_page$ is sitemap_updated_page$
s" <strong>Edit summary</strong>: "
sconstant sitemap_default_edit_summary$
defer sitemap_edit_summary$
' sitemap_default_edit_summary$ is sitemap_edit_summary$
\ ==============================================================
\ Calculated data {{{1
: pid#>taguri ( a -- ca len )
>r s" tag:" domain s+ s" ," s+
r@ created 10 min s+ s" :" s+
r> target_file s+ ;
\ Return the tag URI of a page.
\ Code converted from ForthCMS' `>page-taguri`, by the same author.
\ a = page ID
\ ==============================================================
\ Tags {{{1
: <urlset> ( -- ) echo_cr s" urlset" {html ;
: </urlset> ( -- ) echo_cr s" urlset" html} ;
: <url> ( -- ) echo_cr s" url" {html ;
: </url> ( -- ) echo_cr s" url" html} ;
: <loc> ( -- ) echo_cr s" loc" {html ;
: </loc> ( -- ) echo_cr s" loc" html} ;
: <lastmod> ( -- ) echo_cr s" lastmod" {html ;
: </lastmod> ( -- ) s" lastmod" html} ;
: <changefreq> ( -- ) echo_cr s" changefreq" {html ;
: </changefreq> ( -- ) s" changefreq" html} ;
: <priority> ( -- ) echo_cr s" priority" {html ;
: </priority> ( -- ) s" priority" html} ;
\ ==============================================================
\ sitemap feed {{{1
: sitemap_link ( ca1 len1 ca2 len2 -- )
rel=! href=! [<link/>] ;
\ ca1 len1 = URL
\ ca2 len2 = rel attribute
: sitemap_xhtml_summary{ ( -- )
s" xhtml" type=! <summary> s" http://www.w3.org/1999/xhtml" xmlns=! [<div>] ;
: }sitemap_xhtml_summary ( -- )
[</div>] </summary> ;
: sitemap_feed_author ( -- )
<author> <name> site_author echo </name> </author> ;
: sitemap_feed_id ( -- )
<id> current_lang$ pid$>url echo </id> ;
\ The feed id is the website home page for the current language.
defer sitemap_site_title$ ( -- ca len )
' site_title is sitemap_site_title$
: sitemap_feed_title ( -- )
[<title>] sitemap_site_title$ unmarkup echo [</title>] ;
: sitemap_feed_subtitle ( -- )
<subtitle> site_subtitle unmarkup echo </subtitle> ;
: sitemap_feed_alternate_link ( -- )
current_lang$ 2dup hreflang=! pid$>url s" alternate" sitemap_link ;
: sitemap_feed_selflink ( ca len -- )
current_lang$ hreflang=! current_target_file_url s" self" sitemap_link ;
: sitemap_feed_links ( -- )
sitemap_feed_alternate_link
sitemap_feed_selflink ;
: time_zone ( -- ca len )
s" date +%:z > /tmp/fendo.time_zone.txt" system
s" /tmp/fendo.time_zone.txt" slurp-file
1- ; \ remove the final line feed
\ XXX not used
: sitemap_feed_updated ( -- )
<updated> current_page modified echo </updated> ;
: sitemap_feed_generator ( -- )
<generator> generator echo </generator> ;
: sitemap_feed_icon ( -- )
<icon> site_icon +domain_url echo </icon> ;
: sitemap_feed_header ( -- )
sitemap_feed_title
sitemap_feed_subtitle
sitemap_feed_links
sitemap_feed_icon
sitemap_feed_updated
sitemap_feed_author
sitemap_feed_id
sitemap_feed_generator ;
: (sitemap{) ( -- f )
xhtml? true to xhtml?
open_target
s" <?xml version='1.0' encoding='utf-8'?>" echo
current_lang$ xml:lang=! domain_url xml:base=!
s" http://www.w3.org/2005/sitemap" xmlns=! <feed>
sitemap_feed_header ;
\ Create an sitemap file.
\ f = saved content of `xhtml?`, to be restored by `}sitemap`
: sitemap{ ( -- )
do_page? if .sourcefilename (sitemap{) else skip_page then ;
\ Start the sitemap content, if needed.
\ The end of the content is marked with the `}sitemap` markup.
\ Only one 'sitemap{ ... }sitemap' block is allowed in the page.
: }sitemap ( f -- )
</feed> close_target to xhtml? ;
\ Finish and close the sitemap file.
\ f = saved `xhtml?`
\ ==============================================================
\ sitemap entries {{{1
: sitemap_entry_title ( a -- )
s" xhtml" type=! [<title>] title evaluate_content [</title>] ;
\ a = page ID
: sitemap_entry_id ( a -- )
<id> pid#>taguri echo </id> ;
\ a = page ID
: sitemap_entry_links ( a -- )
dup pid#>lang$ hreflang=! pid#>url s" alternate" sitemap_link ;
\ a = page ID
: sitemap_entry_updated ( a -- )
<updated> modified echo </updated> ;
\ a = page ID
: sitemap_entry_published ( a -- )
<published> created echo </published> ;
\ a = page ID
defer (sitemap_entry_summary)
: sitemap_entry_summary ( -- )
sitemap_xhtml_summary{ (sitemap_entry_summary) }sitemap_xhtml_summary ;
: sitemap_entry_default_summary ( a -- )
<summary> description unmarkup echo </summary> ;
\ a = page ID
: .sitemap_entry_comment ( ca len a -- a )
>r echo_line r> ;
\ a = page ID
: sitemap_entry_updated_summary ( a -- )
[ false ] [if]
\ XXX OLD
[<p>] sitemap_updated_page$ echo_line
dup >r description evaluate_content
r> edit_summary dup
if echo_space evaluate_content else 2drop then
[</p>]
[else]
[<p>] sitemap_updated_page$ echo_line
dup description evaluate_content [</p>]
edit_summary dup if
[<p>] sitemap_edit_summary$ echo_line
echo_space evaluate_content [</p>]
else 2drop then
[then] ;
\ a = page ID
: sitemap_entry_new_summary ( ca len -- )
[<p>] sitemap_new_page$ echo_line
description evaluate_content [</p>] ;
\ ca len = page ID
: set_default_sitemap_entry_summary ( -- )
['] sitemap_entry_default_summary is (sitemap_entry_summary) ;
set_default_sitemap_entry_summary
: sitemap_entry ( ca len -- )
<entry> pid$>pid# >r
r@ sitemap_entry_title
r@ sitemap_entry_id
r@ sitemap_entry_links
r@ sitemap_entry_published
r@ sitemap_entry_updated
r> sitemap_entry_summary
</entry> ;
\ Create an sitemap entry in the sitemap file.
\ ca len = page ID
: (sitemap_entry) ( ca len xt -- )
is (sitemap_entry_summary)
sitemap_entry set_default_sitemap_entry_summary ;
\ Create an sitemap entry in the sitemap file, with non-default summary.
\ ca len = page ID
\ xt = type of sitemap entry summary, new or updated
: sitemap_updated_entry ( ca len -- )
['] sitemap_entry_updated_summary (sitemap_entry) ;
\ Create an sitemap entry in the sitemap file,
\ about an updated page of the site.
\ ca len = page ID
: sitemap_new_entry ( ca len -- )
['] sitemap_entry_new_summary (sitemap_entry) ;
\ Create an sitemap entry in the sitemap file, about a new page of the site.
\ ca len = page ID
.( fendo.addon.sitemap.fs compiled) cr
\ ==============================================================
\ Change log {{{1
\ 2015-10-05: Start, using the code of the Atom module.
\
\ 2017-06-22: Update source style, layout and header.
\
\ 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-14: Define strings constants with `sconstant` instead of
\ `2constant`.
\ vim: filetype=gforth