-
Notifications
You must be signed in to change notification settings - Fork 0
/
gensitemap
executable file
·33 lines (30 loc) · 927 Bytes
/
gensitemap
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
#!/usr/local/bin/php
<?php
$nav = getSitemap("nav/nav.json");
$out = buildSitemap($nav->sidemenu);
print join("\n", $out)."\n";
function buildSitemap($json) {
$out = array();
foreach ($json as $idx=>$item) {
if (property_exists($item, "_include")) {
$item->_children = getSitemap($item->_include);
}
if (property_exists($item, "link")) {
if (!preg_match("/^http/", $item->link)) {
if (!preg_match("/^[\/\.]/", $item->link)) {
$item->link = "/crblog/" . $item->link;
}
$out[] = "https://cdr2.com{$item->link}";
}
}
if (property_exists($item, "_children")) {
$tmp = buildSitemap($item->_children);
$out = array_merge($out, $tmp);
}
}
return $out;
}
function getSitemap($file) {
return json_decode(file_get_contents($file));
}
?>