Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

fix(definitions): gracefully handle sitemap fetch failure in codegen

Thomas Camlong7f8b0121b303
diff --git a/packages/definitions/src/docs/codegen.ts b/packages/definitions/src/docs/codegen.ts
index 6ea123c7f..a4355bd26 100644
--- a/packages/definitions/src/docs/codegen.ts
+++ b/packages/definitions/src/docs/codegen.ts
@@ -56,33 +56,39 @@ const updateSitemapTypeFileAsync = async (sitemapPathType: string) => {
sitemapPathType +
";\n";
- await fs.writeFile(path.join(__dirname, "homarr-docs-sitemap.ts"), content);
+ await fs.writeFile(outputPath, content);
};
-/**
- * This script fetches the sitemap.xml and generates the HomarrDocumentationPath type
- * which is used for typesafe documentation links
- */
-// eslint-disable-next-line no-restricted-syntax
+const slugMapPaths = [
+ ...Object.values(integrationDocSlugs).filter(Boolean).map((slug) => `/docs/integrations/${slug}`),
+ ...Object.values(widgetDocSlugs).filter(Boolean).map((slug) => `/docs/widgets/${slug}`),
+];
+
+const outputPath = path.join(__dirname, "homarr-docs-sitemap.ts");
+
const main = async () => {
- const sitemapXml = await fetchSitemapAsync();
- const sitemapData = parseXml(sitemapXml);
- const paths = mapSitemapXmlToPaths(sitemapData);
- paths.push("/sitemap.xml");
+ let paths: string[];
+ try {
+ const sitemapXml = await fetchSitemapAsync();
+ const sitemapData = parseXml(sitemapXml);
+ paths = mapSitemapXmlToPaths(sitemapData);
+ } catch {
+ const exists = await fs.access(outputPath).then(() => true, () => false);
+ if (exists) {
+ console.warn("Could not fetch sitemap from homarr.dev, keeping existing generated file");
+ return;
+ }
+ console.warn("Could not fetch sitemap from homarr.dev and no existing file, generating from slug maps only");
+ paths = [];
+ }
- const slugMapPaths = [
- ...Object.values(integrationDocSlugs)
- .filter(Boolean)
- .map((slug) => `/docs/integrations/${slug}`),
- ...Object.values(widgetDocSlugs)
- .filter(Boolean)
- .map((slug) => `/docs/widgets/${slug}`),
- ];
+ paths.push("/sitemap.xml");
for (const p of slugMapPaths) {
if (!paths.includes(p)) {
paths.push(p);
}
}
+
const sitemapPathType = createSitemapPathType(paths);
await updateSitemapTypeFileAsync(sitemapPathType);
};