@canopy-iiif/app 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/build/sitemap.js
CHANGED
|
@@ -3,6 +3,8 @@ const { logLine } = require('./log');
|
|
|
3
3
|
|
|
4
4
|
const DEFAULT_CHANGEFREQ = 'monthly';
|
|
5
5
|
const DEFAULT_PRIORITY = '0.5';
|
|
6
|
+
const MAX_URLS_PER_SITEMAP = 1000;
|
|
7
|
+
const SITEMAP_INDEX_BASENAME = 'sitemap.xml';
|
|
6
8
|
|
|
7
9
|
function escapeXml(value) {
|
|
8
10
|
return String(value || '')
|
|
@@ -44,12 +46,7 @@ function collectAbsoluteUrls(iiifRecords, pageRecords) {
|
|
|
44
46
|
return Array.from(urls.values()).sort((a, b) => a.localeCompare(b));
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
const urls = collectAbsoluteUrls(iiifRecords, pageRecords);
|
|
49
|
-
if (!urls.length) {
|
|
50
|
-
logLine('• No URLs to write to sitemap', 'yellow');
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
49
|
+
function buildUrlsetXml(urls) {
|
|
53
50
|
const rows = urls.map((loc) => {
|
|
54
51
|
const escapedLoc = escapeXml(loc);
|
|
55
52
|
return [
|
|
@@ -60,16 +57,79 @@ async function writeSitemap(iiifRecords, pageRecords) {
|
|
|
60
57
|
' </url>',
|
|
61
58
|
].join('\n');
|
|
62
59
|
});
|
|
63
|
-
|
|
60
|
+
return [
|
|
64
61
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
65
62
|
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
66
63
|
rows.join('\n'),
|
|
67
64
|
'</urlset>',
|
|
68
65
|
'',
|
|
69
66
|
].join('\n');
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function buildSitemapIndexXml(entries) {
|
|
70
|
+
const rows = entries.map((entry) => {
|
|
71
|
+
const escapedLoc = escapeXml(entry.loc);
|
|
72
|
+
return [' <sitemap>', ` <loc>${escapedLoc}</loc>`, ' </sitemap>'].join('\n');
|
|
73
|
+
});
|
|
74
|
+
return [
|
|
75
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
76
|
+
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
77
|
+
rows.join('\n'),
|
|
78
|
+
'</sitemapindex>',
|
|
79
|
+
'',
|
|
80
|
+
].join('\n');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function chunkList(list, chunkSize) {
|
|
84
|
+
const chunks = [];
|
|
85
|
+
if (!Array.isArray(list) || chunkSize <= 0) return chunks;
|
|
86
|
+
for (let i = 0; i < list.length; i += chunkSize) {
|
|
87
|
+
chunks.push(list.slice(i, i + chunkSize));
|
|
88
|
+
}
|
|
89
|
+
return chunks;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function cleanupLegacySitemaps() {
|
|
93
|
+
let entries;
|
|
94
|
+
try {
|
|
95
|
+
entries = await fsp.readdir(OUT_DIR);
|
|
96
|
+
} catch (_) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const deletions = entries
|
|
100
|
+
.filter((name) => /^sitemap-\d+\.xml$/i.test(name))
|
|
101
|
+
.map((name) =>
|
|
102
|
+
fsp
|
|
103
|
+
.unlink(path.join(OUT_DIR, name))
|
|
104
|
+
.catch(() => {})
|
|
105
|
+
);
|
|
106
|
+
await Promise.all(deletions);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function writeSitemap(iiifRecords, pageRecords) {
|
|
110
|
+
const urls = collectAbsoluteUrls(iiifRecords, pageRecords);
|
|
111
|
+
if (!urls.length) {
|
|
112
|
+
await cleanupLegacySitemaps();
|
|
113
|
+
logLine('• No URLs to write to sitemap', 'yellow');
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
await cleanupLegacySitemaps();
|
|
117
|
+
|
|
118
|
+
const chunks = chunkList(urls, MAX_URLS_PER_SITEMAP);
|
|
119
|
+
const indexEntries = [];
|
|
120
|
+
for (let i = 0; i < chunks.length; i += 1) {
|
|
121
|
+
const fileName = `sitemap-${i + 1}.xml`;
|
|
122
|
+
const dest = path.join(OUT_DIR, fileName);
|
|
123
|
+
await fsp.writeFile(dest, buildUrlsetXml(chunks[i]), 'utf8');
|
|
124
|
+
indexEntries.push({ loc: absoluteUrl(fileName) });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const indexDest = path.join(OUT_DIR, SITEMAP_INDEX_BASENAME);
|
|
128
|
+
await fsp.writeFile(indexDest, buildSitemapIndexXml(indexEntries), 'utf8');
|
|
129
|
+
logLine(
|
|
130
|
+
`✓ Wrote sitemap index (${chunks.length} files, ${urls.length} urls total)`,
|
|
131
|
+
'cyan'
|
|
132
|
+
);
|
|
73
133
|
}
|
|
74
134
|
|
|
75
135
|
module.exports = { writeSitemap };
|
package/package.json
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
--hero-height: 520px;
|
|
12
12
|
--hero-bg-start: var(--color-gray-50);
|
|
13
13
|
--hero-bg-mid: var(--color-accent-100);
|
|
14
|
-
--hero-bg-end: var(--color-accent-
|
|
15
|
-
--hero-dot-bg: var(--color-accent-
|
|
14
|
+
--hero-bg-end: var(--color-accent-300);
|
|
15
|
+
--hero-dot-bg: var(--color-accent-400);
|
|
16
16
|
--hero-dot-active-bg: var(--color-accent-700);
|
|
17
17
|
|
|
18
18
|
background: linear-gradient(
|
|
@@ -137,8 +137,9 @@
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
.canopy-interstitial__description {
|
|
140
|
-
font-size: 0.
|
|
141
|
-
|
|
140
|
+
font-size: 0.9222rem;
|
|
141
|
+
font-weight: 700;
|
|
142
|
+
color: var(--color-accent-700);
|
|
142
143
|
font-family: var(--font-mono);
|
|
143
144
|
}
|
|
144
145
|
}
|
package/ui/styles/index.css
CHANGED
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
}
|
|
78
78
|
code {
|
|
79
79
|
font-family: var(--font-mono);
|
|
80
|
-
font-size: 0.
|
|
80
|
+
font-size: 0.9222rem;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
hr {
|
|
@@ -869,8 +869,8 @@ section[data-footnotes] ul li,
|
|
|
869
869
|
--hero-height: 520px;
|
|
870
870
|
--hero-bg-start: var(--color-gray-50);
|
|
871
871
|
--hero-bg-mid: var(--color-accent-100);
|
|
872
|
-
--hero-bg-end: var(--color-accent-
|
|
873
|
-
--hero-dot-bg: var(--color-accent-
|
|
872
|
+
--hero-bg-end: var(--color-accent-300);
|
|
873
|
+
--hero-dot-bg: var(--color-accent-400);
|
|
874
874
|
--hero-dot-active-bg: var(--color-accent-700);
|
|
875
875
|
background: linear-gradient(173deg, var(--hero-bg-start) 5rem, var(--hero-bg-mid) 61.8%, var(--hero-bg-end) 100%);
|
|
876
876
|
min-height: var(--hero-height);
|
|
@@ -973,8 +973,9 @@ section[data-footnotes] ul li,
|
|
|
973
973
|
padding: 1rem 1.618rem;
|
|
974
974
|
}
|
|
975
975
|
.canopy-interstitial--hero-breadcrumb .canopy-interstitial__description {
|
|
976
|
-
font-size: 0.
|
|
977
|
-
|
|
976
|
+
font-size: 0.9222rem;
|
|
977
|
+
font-weight: 700;
|
|
978
|
+
color: var(--color-accent-700);
|
|
978
979
|
font-family: var(--font-mono);
|
|
979
980
|
}
|
|
980
981
|
.canopy-interstitial__breadcrumb {
|