-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rollback nuxt-simple-sitemap integration
- Loading branch information
Showing
5 changed files
with
163 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { IncomingMessage, ServerResponse } from 'node:http' | ||
import { defineEventHandler } from 'h3' | ||
|
||
import { generateXslStylesheet } from '~/node_modules/nuxt-simple-sitemap/dist/runtime/util/builder' | ||
|
||
// Import by node_modules because access to internal module content | ||
|
||
async function stylesheet( | ||
req: IncomingMessage, | ||
res: ServerResponse<IncomingMessage>, | ||
) { | ||
res.write(generateXslStylesheet()) | ||
res.statusCode = 200 | ||
res.end() | ||
} | ||
|
||
export default defineEventHandler( | ||
async event => await stylesheet(event.node.req, event.node.res), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import type { IncomingMessage, ServerResponse } from 'node:http' | ||
import { defineEventHandler } from 'h3' | ||
|
||
import type { SitemapEntry } from '~/node_modules/nuxt-simple-sitemap/dist/module' | ||
import type { | ||
BuildSitemapOptions, | ||
} from '~/node_modules/nuxt-simple-sitemap/dist/runtime/util/builder' | ||
import { | ||
buildSitemap, | ||
} from '~/node_modules/nuxt-simple-sitemap/dist/runtime/util/builder' | ||
import { getMenu } from '~/lib/apiMenu' | ||
import { getPois } from '~/lib/apiPois' | ||
import { vidos } from '~/lib/config' | ||
import { vidoConfigResolve } from '~/plugins/vido-config' | ||
import type { VidoConfig } from '~/utils/types-config' | ||
|
||
// Import by node_modules because access to internal module content | ||
|
||
async function manifest( | ||
req: IncomingMessage, | ||
res: ServerResponse<IncomingMessage>, | ||
) { | ||
const hostname = (req.headers['x-forwarded-host'] || req.headers.host) as | ||
| string | ||
| undefined | ||
if (hostname) { | ||
const vido: VidoConfig = vidoConfigResolve(hostname, vidos()) | ||
|
||
const menu = getMenu(vido).then(menuItem => | ||
menuItem | ||
.filter(menuItem => menuItem.category && menuItem.id) | ||
.map(menuCategory => ({ | ||
url: `/${menuCategory.id}/`, | ||
})), | ||
) | ||
|
||
const pois = getPois(vido).then(apiPois => | ||
apiPois.features.map(poi => ({ | ||
url: `/poi/${poi.properties.metadata.id}/details`, | ||
lastmod: poi.properties.metadata.updated_at, | ||
})), | ||
) | ||
|
||
const entries: SitemapEntry[] = (await Promise.all([menu, pois])).flat( | ||
1, | ||
) | ||
|
||
entries.push({ | ||
url: '/', | ||
}) | ||
entries.push({ | ||
url: '/embedded/', | ||
}) | ||
|
||
const options: BuildSitemapOptions = { | ||
sitemapConfig: { | ||
dynamicUrlsApiEndpoint: '/__sitemap', | ||
discoverImages: false, | ||
xsl: '/sitemap-style.xsl', | ||
defaults: {}, | ||
enabled: true, | ||
trailingSlash: false, | ||
siteUrl: `https://${hostname}`, | ||
autoLastmod: false, | ||
inferStaticPagesAsRoutes: false, | ||
// sitemaps?: boolean | Record<string, Partial<SitemapRoot>>; | ||
hasApiRoutesUrl: false, | ||
hasPrerenderedRoutesPayload: false, | ||
isNuxtContentDocumentDriven: false, | ||
urls: entries, | ||
sitemapName: 'sitemap.xml' | ||
}, | ||
baseURL: `https://${hostname}`, | ||
getRouteRulesForPath(_path: string): Record<string, any> { | ||
return {} | ||
}, | ||
} | ||
|
||
res.write( | ||
await buildSitemap({...options, sitemapName: 'default'}) | ||
Check failure on line 80 in server/routes/sitemap.xml.ts GitHub Actions / Lint code base (ubuntu-latest, 18)
Check failure on line 80 in server/routes/sitemap.xml.ts GitHub Actions / Lint code base (ubuntu-latest, 18)
|
||
) | ||
|
||
res.statusCode = 200 | ||
res.end() | ||
} | ||
else { | ||
res.statusCode = 500 | ||
res.end() | ||
} | ||
} | ||
|
||
export default defineEventHandler( | ||
async event => await manifest(event.node.req, event.node.res), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters