@writedocs/generator 0.4.2 → 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 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/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@writedocs/generator",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Static site generator for docs — a writedocs.json + MDX folder in, a static site out.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -84,4 +84,4 @@
84
84
  "devDependencies": {
85
85
  "esbuild": "0.28.2"
86
86
  }
87
- }
87
+ }
@@ -25,11 +25,17 @@ interface Props {
25
25
  const { config } = Astro.props as Props;
26
26
 
27
27
  const askAiLoaderScript = `window.DocsBotAI=window.DocsBotAI||{},DocsBotAI.init=function(e){return new Promise((t,r)=>{var n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src="https://widget.docsbot.ai/chat.js";let o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(n,o),n.addEventListener("load",()=>{let n;Promise.all([new Promise((t,r)=>{window.DocsBotAI.mount(Object.assign({}, e)).then(t).catch(r)}),(n=function e(t){return new Promise(e=>{if(document.querySelector(t))return e(document.querySelector(t));let r=new MutationObserver(n=>{if(document.querySelector(t))return e(document.querySelector(t)),r.disconnect()});r.observe(document.body,{childList:!0,subtree:!0})})})("#docsbotai-root"),]).then(()=>t()).catch(r)}),n.addEventListener("error",e=>{r(e.message)})})};`;
28
- const askAiInitScript = config.integrations.askAi
29
- ? `DocsBotAI.init(${JSON.stringify({ id: config.integrations.askAi.id })});`
28
+ // WRITEDOCS_ASK_AI_ID tem precedência sobre o writedocs.json, pelo mesmo
29
+ // motivo do WRITEDOCS_DISABLE_WATERMARK em Sidebar.astro: quem roda o build
30
+ // (CI, env da hospedagem) define o bot sem mexer no conteúdo versionado.
31
+ // Não é segredo - o id sai em texto puro no HTML de toda página. String
32
+ // vazia conta como não definida e cai no valor do JSON.
33
+ const askAiId = process.env.WRITEDOCS_ASK_AI_ID || config.integrations.askAi?.id;
34
+ const askAiInitScript = askAiId
35
+ ? `DocsBotAI.init(${JSON.stringify({ id: askAiId })});`
30
36
  : null;
31
37
  ---
32
- {config.integrations.askAi && (
38
+ {askAiId && (
33
39
  <>
34
40
  <script is:inline set:html={askAiLoaderScript} />
35
41
  {askAiInitScript && <script is:inline set:html={askAiInitScript} />}