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
|
define_type(
'sitemap',
-namespace='google_',
-prototype,
-description='Custom type for creating Google Sitemaps.'
);
local('urls' = array);
define_tag(
'addurl',
-req='loc', -type='string', -copy,
-opt='lastmod', -type='date',
-opt='changefreq', -type='string',
-opt='priority', -type='decimal'
);
fail_if(
(!valid_url(#loc) || #loc->size >= 2048),
-1,
'Location must be a valid URL and less than 2048 characters.'
);
#loc = encode_xml(decode_xml(#loc)); // avoid double encoding
local_defined('lastmod') ? #lastmod->setformat('%Y-%m-%d');
if(local_defined('changefreq'));
local('freqs') = array(
'always',
'hourly',
'daily',
'weekly',
'monthly',
'yearly',
'never'
);
#freqs !>> #changefreq ? #changefreq = null;
else;
local('changefreq' = null);
/if;
if(local_defined('priority'));
select(true);
case(#priority < 0.0);
#priority = 0.0;
case(#priority > 1.0);
#priority = 1.0;
case;
#priority->setformat( -precision=1);
/select;
else;
local('priority' = 0.5);
/if;
local('out' = map);
#out->insert('loc' = #loc);
#out->insert('lastmod' = #lastmod);
#out->insert('changefreq' = #changefreq);
#out->insert('priority' = #priority);
self->urls->insert(#out);
/define_tag;
define_tag('createnode', -req='in');
local('out') = xml('<url />');
#out->newchild('loc')->addcontent(#in->find('loc'));
#in->find('lastmod') != null ? #out->newchild('lastmod')->addcontent(#in->find('lastmod'));
#in->find('changefreq') != '' ? #out->newchild('changefreq')->addcontent(#in->find('changefreq'));
#out->newchild('priority')->addcontent(#in->find('priority'));
return(@#out);
/define_tag;
define_tag('output');
local('out') = xml('\
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd" />
\ ');
iterate(self->urls, local('i'));
#out->addchild(self->createnode(#i));
/iterate;
return('<?xml version="1.0" encoding="UTF-8"?>\n' + #out);
/define_tag;
define_tag('onConvert');
return(@self->output);
/define_tag;
define_tag('save', -req='path');
local('filepath' = #path);
#filepath->removetrailing('/')&append('/sitemap.gz');
file_write(
#filepath,
compress_gzip(self->output),
-fileoverwrite
);
/define_tag;
/define_type;
|