Skip to content

Commit f887426

Browse files
committed
Another possible fix for sitemap.xml
1 parent 5edd08e commit f887426

4 files changed

Lines changed: 87 additions & 3 deletions

File tree

docs/.vitepress/config.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { defineConfig } from 'vitepress'
2+
import { SitemapStream } from 'sitemap'
3+
import { createWriteStream } from 'node:fs'
4+
import { resolve } from 'node:path'
25

36
// https://vitepress.dev/reference/site-config
47
export default defineConfig({
58
title: "PS4 Linux Tutorial",
69
description: "A simple and modern guide on how to install Linux on PS4 systems.",
710
base: "/ps4-linux-tutorial/",
8-
sitemap: {
9-
hostname: 'https://dionkill.github.io/ps4-linux-tutorial/'
10-
},
1111

1212
// Metadata and favicon
1313
head: [
@@ -33,6 +33,24 @@ export default defineConfig({
3333
['meta', { name: 'twitter:image', content: 'https://dionkill.github.io/ps4-linux-tutorial/preview.png' }],
3434
],
3535

36+
buildEnd: async ({ outDir }) => {
37+
const sitemap = new SitemapStream({ hostname: 'https://dionkill.github.io/ps4-linux-tutorial/' })
38+
const pages = await createContentLoader('*.md').load()
39+
const writeStream = createWriteStream(resolve(outDir, 'sitemap.xml'))
40+
41+
sitemap.pipe(writeStream)
42+
pages.forEach((page) => sitemap.write(
43+
page.url
44+
// If `cleanUrls is enabled`
45+
.replace(/index$/g, '')
46+
// Optional: if Markdown files are located in a subfolder
47+
.replace(/^\/docs/, '')
48+
))
49+
sitemap.end()
50+
51+
await new Promise((r) => writeStream.on('finish', r))
52+
},
53+
3654
// Theme configuration
3755
themeConfig: {
3856
// https://vitepress.dev/reference/default-theme-config
@@ -215,6 +233,7 @@ export default defineConfig({
215233
],
216234

217235
// Custom added stuff
236+
cleanUrls: 'true',
218237

219238
socialLinks: [
220239
{ icon: 'github', link: 'https://github.com/DionKill/ps4-linux-tutorial/' }

docs/public/robots.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
User-agent: *
2+
Allow: /
3+
4+
Sitemap: https://dionkill.github.io/ps4-linux-tutorial/sitemap.xml

package-lock.json

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
"docs:dev": "vitepress dev docs",
77
"docs:build": "vitepress build docs",
88
"docs:preview": "vitepress preview docs"
9+
},
10+
"dependencies": {
11+
"sitemap": "^9.0.0"
912
}
1013
}

0 commit comments

Comments
 (0)