Skip to content

Commit

Permalink
feat: rollback nuxt-simple-sitemap integration
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Jan 29, 2024
1 parent b75781b commit d2ed9a3
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 25 deletions.
6 changes: 6 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export default antfu(
'vue/no-unused-refs': 0,
},
},
{
files: ['**/*.ts'],
rules: {
'antfu/no-import-node-modules-by-path': 0,
},
},
{
rules: {
'node/prefer-global/process': 0,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"msw": "^1.2.2",
"node-sass": "^9.0.0",
"nuxt": "^3.2.3",
"nuxt-simple-sitemap": "^2.7.0",
"postcss": "^8.4.24",
"postcss-html": "^1.6.0",
"sass": "^1.63.4",
Expand Down
19 changes: 19 additions & 0 deletions server/routes/sitemap-style.xsl.ts
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),
)
94 changes: 94 additions & 0 deletions server/routes/sitemap.xml.ts
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'

Check failure on line 71 in server/routes/sitemap.xml.ts

View workflow job for this annotation

GitHub Actions / Lint code base (ubuntu-latest, 18)

Missing trailing comma
},
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

View workflow job for this annotation

GitHub Actions / Lint code base (ubuntu-latest, 18)

A space is required after '{'

Check failure on line 80 in server/routes/sitemap.xml.ts

View workflow job for this annotation

GitHub Actions / Lint code base (ubuntu-latest, 18)

A space is required before '}'

Check failure on line 80 in server/routes/sitemap.xml.ts

View workflow job for this annotation

GitHub Actions / Lint code base (ubuntu-latest, 18)

Missing trailing comma
)

res.statusCode = 200
res.end()
}
else {
res.statusCode = 500
res.end()
}
}

export default defineEventHandler(
async event => await manifest(event.node.req, event.node.res),
)
68 changes: 43 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,31 @@ __metadata:
languageName: node
linkType: hard

"@nuxt/kit@npm:3.5.3, @nuxt/kit@npm:^3.4.1, @nuxt/kit@npm:^3.5.0, @nuxt/kit@npm:^3.5.3":
version: 3.5.3
resolution: "@nuxt/kit@npm:3.5.3"
dependencies:
"@nuxt/schema": 3.5.3
c12: ^1.4.1
consola: ^3.1.0
defu: ^6.1.2
globby: ^13.1.4
hash-sum: ^2.0.0
ignore: ^5.2.4
jiti: ^1.18.2
knitwork: ^1.0.0
mlly: ^1.4.0
pathe: ^1.1.1
pkg-types: ^1.0.3
scule: ^1.0.0
semver: ^7.5.1
unctx: ^2.3.1
unimport: ^3.0.7
untyped: ^1.3.2
checksum: 0139aa67b4e76f9d23910cec26d3f727413dcdb9e5d5e3e06314256325e0341436651f3b04f0ec3afb3a9b8facca771123fc716adb319f26de16e2610ccd250a
languageName: node
linkType: hard

"@nuxt/kit@npm:^3.0.0-rc.11":
version: 3.3.1
resolution: "@nuxt/kit@npm:3.3.1"
Expand Down Expand Up @@ -2376,31 +2401,6 @@ __metadata:
languageName: node
linkType: hard

"@nuxt/kit@npm:^3.4.1, @nuxt/kit@npm:^3.5.0, @nuxt/kit@npm:^3.5.3":
version: 3.5.3
resolution: "@nuxt/kit@npm:3.5.3"
dependencies:
"@nuxt/schema": 3.5.3
c12: ^1.4.1
consola: ^3.1.0
defu: ^6.1.2
globby: ^13.1.4
hash-sum: ^2.0.0
ignore: ^5.2.4
jiti: ^1.18.2
knitwork: ^1.0.0
mlly: ^1.4.0
pathe: ^1.1.1
pkg-types: ^1.0.3
scule: ^1.0.0
semver: ^7.5.1
unctx: ^2.3.1
unimport: ^3.0.7
untyped: ^1.3.2
checksum: 0139aa67b4e76f9d23910cec26d3f727413dcdb9e5d5e3e06314256325e0341436651f3b04f0ec3afb3a9b8facca771123fc716adb319f26de16e2610ccd250a
languageName: node
linkType: hard

"@nuxt/schema@npm:3.2.0":
version: 3.2.0
resolution: "@nuxt/schema@npm:3.2.0"
Expand Down Expand Up @@ -3033,6 +3033,7 @@ __metadata:
msw: ^1.2.2
node-sass: ^9.0.0
nuxt: ^3.2.3
nuxt-simple-sitemap: ^2.7.0
opening_hours: ^3.8.0
pinia: ^2.0.33
pinia-shared-state: ^0.4.2
Expand Down Expand Up @@ -11423,6 +11424,23 @@ __metadata:
languageName: node
linkType: hard

"nuxt-simple-sitemap@npm:^2.7.0":
version: 2.7.0
resolution: "nuxt-simple-sitemap@npm:2.7.0"
dependencies:
"@nuxt/kit": 3.5.3
chalk: ^5.2.0
defu: ^6.1.2
escape-string-regexp: ^5.0.0
globby: ^13.1.4
knitwork: ^1.0.0
pathe: ^1.1.1
radix3: ^1.0.1
ufo: ^1.1.2
checksum: fe072cfc784335fa4c496da4d556b7aa6979f1d64880ce973279227d785a30bf1cb2c4a467bcfe32ed121d6716c726b5d23dd4e962a6494734094ec1bfe3803c
languageName: node
linkType: hard

"nuxt@npm:^3.2.3":
version: 3.2.3
resolution: "nuxt@npm:3.2.3"
Expand Down

0 comments on commit d2ed9a3

Please sign in to comment.