@writedocs/generator 0.4.3 → 0.4.4
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/astro.config.mjs +41 -0
- package/package.json +1 -1
package/astro.config.mjs
CHANGED
|
@@ -147,6 +147,40 @@ function collectNoindexIds(rootContentDir) {
|
|
|
147
147
|
|
|
148
148
|
const noindexIds = siteUrl ? collectNoindexIds(contentDir) : new Set();
|
|
149
149
|
|
|
150
|
+
/** O @astrojs/sitemap sempre grava um sitemap-index.xml apontando para
|
|
151
|
+
* sitemap-0.xml, sitemap-1.xml, ... - mesmo quando há um arquivo só, que é
|
|
152
|
+
* o caso de todo site de docs abaixo de 50.000 páginas. Aqui o único
|
|
153
|
+
* sitemap-0.xml vira sitemap.xml (o endereço que crawler e ferramenta de
|
|
154
|
+
* SEO procuram primeiro) e o índice é apagado. Com mais de um arquivo o
|
|
155
|
+
* índice é necessário (o protocolo não permite um único arquivo acima de
|
|
156
|
+
* 50.000 URLs), então tudo fica como o plugin gravou. Um sitemap.xml
|
|
157
|
+
* vindo do public/ do próprio site também não é sobrescrito. */
|
|
158
|
+
function singleSitemapFile() {
|
|
159
|
+
return {
|
|
160
|
+
name: 'writedocs-single-sitemap',
|
|
161
|
+
hooks: {
|
|
162
|
+
'astro:build:done': ({ dir }) => {
|
|
163
|
+
const outDir = fileURLToPath(dir);
|
|
164
|
+
const chunks = fs.readdirSync(outDir).filter((f) => /^sitemap-\d+\.xml$/.test(f));
|
|
165
|
+
const target = path.join(outDir, 'sitemap.xml');
|
|
166
|
+
if (chunks.length !== 1) {
|
|
167
|
+
console.log(`[writedocs] ${chunks.length} sitemap files generated - keeping sitemap-index.xml.`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (fs.existsSync(target)) {
|
|
171
|
+
console.log('[writedocs] public/sitemap.xml exists - keeping it and the generated sitemap-index.xml.');
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
fs.renameSync(path.join(outDir, chunks[0]), target);
|
|
175
|
+
fs.rmSync(path.join(outDir, 'sitemap-index.xml'), { force: true });
|
|
176
|
+
// O próprio plugin acabou de logar "sitemap-index.xml created"; esta
|
|
177
|
+
// linha diz o que de fato ficou no build.
|
|
178
|
+
console.log(`[writedocs] Replaced ${chunks[0]} + sitemap-index.xml with a single sitemap.xml.`);
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
150
184
|
// writedocs.json's `redirects` array -> Astro's own `redirects` config option
|
|
151
185
|
// (a plain `{ [source]: destination }` record - see redirectSchema in
|
|
152
186
|
// lib/config.ts for why there's no `permanent`/status-code field: this
|
|
@@ -207,12 +241,19 @@ export default defineConfig({
|
|
|
207
241
|
...(siteUrl
|
|
208
242
|
? [
|
|
209
243
|
sitemap({
|
|
244
|
+
// Teto do protocolo de sitemap por arquivo (o default do
|
|
245
|
+
// @astrojs/sitemap é 45.000). Até aqui, tudo cabe num único
|
|
246
|
+
// sitemap.xml - ver singleSitemapFile() abaixo.
|
|
247
|
+
entryLimit: 50000,
|
|
210
248
|
filter: (page) => {
|
|
211
249
|
const pathname = new URL(page).pathname;
|
|
212
250
|
const id = normalizeEntryId(pathname);
|
|
213
251
|
return !noindexIds.has(id);
|
|
214
252
|
},
|
|
215
253
|
}),
|
|
254
|
+
// Precisa vir depois do sitemap(): o Astro roda os hooks
|
|
255
|
+
// astro:build:done na ordem deste array, um de cada vez.
|
|
256
|
+
singleSitemapFile(),
|
|
216
257
|
]
|
|
217
258
|
: []),
|
|
218
259
|
// Lets styles.favicon/styles.logo/styles.background.images/seo.ogImage/
|