Skip to content

Commit 773f7b2

Browse files
committed
feat: sitemaps
1 parent 9c6a317 commit 773f7b2

File tree

3 files changed

+128
-4
lines changed

3 files changed

+128
-4
lines changed

nuxt.config.js

+56-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default {
4141

4242
buildModules: [],
4343

44-
modules: ['@nuxtjs/axios', '@nuxtjs/dotenv'],
44+
modules: ['@nuxtjs/axios', '@nuxtjs/dotenv', '@nuxtjs/sitemap'],
4545

4646
axios: {},
4747

@@ -61,6 +61,61 @@ export default {
6161
}
6262
},
6363

64+
sitemap: {
65+
hostname: 'https://nuepress.kmr.io',
66+
path: '/sitemap.xml',
67+
sitemaps: [
68+
{
69+
path: '/sitemap-articles.xml',
70+
routes: async () => {
71+
const { data } = await axios.get(process.env.WORDPRESS_API_URL + '/wp/v2/posts', {
72+
params: { orderby: 'date', per_page: 1000000 }
73+
});
74+
return data.map(article => ({
75+
url: `/${article.slug}`,
76+
lastmod: article.modified
77+
}));
78+
}
79+
},
80+
{
81+
path: '/sitemap-pages.xml',
82+
routes: async () => {
83+
const { data } = await axios.get(process.env.WORDPRESS_API_URL + '/wp/v2/pages', {
84+
params: { orderby: 'date', per_page: 1000000 }
85+
});
86+
return data.map(page => ({
87+
url: `/${page.slug}`,
88+
lastmod: page.modified
89+
}));
90+
}
91+
},
92+
{
93+
path: '/sitemap-topics.xml',
94+
routes: async () => {
95+
const { data } = await axios.get(process.env.WORDPRESS_API_URL + '/wp/v2/categories', {
96+
params: { per_page: 1000000 }
97+
});
98+
return data.map(topic => ({
99+
url: `/${topic.slug}`,
100+
lastmod: topic.modified
101+
}));
102+
}
103+
},
104+
{
105+
path: '/sitemap-users.xml',
106+
routes: async () => {
107+
const { data } = await axios.get(process.env.WORDPRESS_API_URL + '/wp/v2/users', {
108+
params: { per_page: 1000000 }
109+
});
110+
return data.map(user => ({
111+
url: `/${user.slug}`,
112+
lastmod: user.modified
113+
}));
114+
}
115+
}
116+
]
117+
},
118+
64119
generate: {
65120
async routes() {
66121
let posts = await axios

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"dependencies": {
1616
"@nuxtjs/axios": "^5.9.3",
17+
"@nuxtjs/sitemap": "^2.0.1",
1718
"date-fns": "^2.9.0",
1819
"lg-fullscreen.js": "^1.1.0",
1920
"lg-pager.js": "^1.0.0",

yarn.lock

+71-3
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,19 @@
11651165
consola "^2.5.6"
11661166
http-proxy-middleware "^0.19.1"
11671167

1168+
"@nuxtjs/sitemap@^2.0.1":
1169+
version "2.0.1"
1170+
resolved "https://registry.yarnpkg.com/@nuxtjs/sitemap/-/sitemap-2.0.1.tgz#084c2b2bf3ded2b37886507e7ab63021f1b9e3d6"
1171+
integrity sha512-/0VrxWj8Q9asxvGcvb4o5VeCrPjK/X2bOOriI59nfXop6e95GdSQsF2vtAe3WH6V89M3Q3tM7ytTuh6OeH7YYw==
1172+
dependencies:
1173+
async-cache "^1.1.0"
1174+
consola "^2.11.0"
1175+
fs-extra "^8.1.0"
1176+
is-https "^1.0.0"
1177+
lodash.unionby "^4.8.0"
1178+
minimatch "^3.0.4"
1179+
sitemap "^4.1.1"
1180+
11681181
"@nuxtjs/tailwindcss@^1.3.1":
11691182
version "1.3.1"
11701183
resolved "https://registry.yarnpkg.com/@nuxtjs/tailwindcss/-/tailwindcss-1.3.1.tgz#f582ccb7c6eb2279dd773e04fe1720fc52d4421d"
@@ -1203,16 +1216,33 @@
12031216
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440"
12041217
integrity sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==
12051218

1219+
"@types/node@*":
1220+
version "13.5.2"
1221+
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.5.2.tgz#3de53b55fd39efc428a901a0f6db31f761cfa131"
1222+
integrity sha512-Fr6a47c84PRLfd7M7u3/hEknyUdQrrBA6VoPmkze0tcflhU5UnpWEX2kn12ktA/lb+MNHSqFlSiPHIHsaErTPA==
1223+
12061224
"@types/node@^10.11.7":
12071225
version "10.17.14"
12081226
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.17.14.tgz#b6c60ebf2fb5e4229fdd751ff9ddfae0f5f31541"
12091227
integrity sha512-G0UmX5uKEmW+ZAhmZ6PLTQ5eu/VPaT+d/tdLd5IFsKRPcbe6lPxocBtcYBFSaLaCW8O60AX90e91Nsp8lVHCNw==
12101228

1229+
"@types/node@^12.0.2":
1230+
version "12.12.26"
1231+
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.26.tgz#213e153babac0ed169d44a6d919501e68f59dea9"
1232+
integrity sha512-UmUm94/QZvU5xLcUlNR8hA7Ac+fGpO1EG/a8bcWVz0P0LqtxFmun9Y2bbtuckwGboWJIT70DoWq1r3hb56n3DA==
1233+
12111234
"@types/q@^1.5.1":
12121235
version "1.5.2"
12131236
resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.2.tgz#690a1475b84f2a884fd07cd797c00f5f31356ea8"
12141237
integrity sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw==
12151238

1239+
"@types/sax@^1.2.0":
1240+
version "1.2.1"
1241+
resolved "https://registry.yarnpkg.com/@types/sax/-/sax-1.2.1.tgz#e0248be936ece791a82db1a57f3fb5f7c87e8172"
1242+
integrity sha512-dqYdvN7Sbw8QT/0Ci5rhjE4/iCMJEM0Y9rHpCu+gGXD9Lwbz28t6HI2yegsB6BoV1sShRMU6lAmAcgRjmFy7LA==
1243+
dependencies:
1244+
"@types/node" "*"
1245+
12161246
"@vue/babel-helper-vue-jsx-merge-props@^1.0.0":
12171247
version "1.0.0"
12181248
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.0.0.tgz#048fe579958da408fb7a8b2a3ec050b50a661040"
@@ -1607,6 +1637,11 @@ are-we-there-yet@~1.1.2:
16071637
delegates "^1.0.0"
16081638
readable-stream "^2.0.6"
16091639

1640+
arg@^4.1.1:
1641+
version "4.1.2"
1642+
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.2.tgz#e70c90579e02c63d80e3ad4e31d8bfdb8bd50064"
1643+
integrity sha512-+ytCkGcBtHZ3V2r2Z06AncYO8jz46UEamcspGoU8lHcEbpn6J77QK0vdWvChsclg/tM5XIJC5tnjmPp7Eq6Obg==
1644+
16101645
argparse@^1.0.7:
16111646
version "1.0.10"
16121647
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
@@ -1688,6 +1723,13 @@ assign-symbols@^1.0.0:
16881723
resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367"
16891724
integrity sha1-WWZ/QfrdTyDMvCu5a41Pf3jsA2c=
16901725

1726+
async-cache@^1.1.0:
1727+
version "1.1.0"
1728+
resolved "https://registry.yarnpkg.com/async-cache/-/async-cache-1.1.0.tgz#4a9a5a89d065ec5d8e5254bd9ee96ba76c532b5a"
1729+
integrity sha1-SppaidBl7F2OUlS9nulrp2xTK1o=
1730+
dependencies:
1731+
lru-cache "^4.0.0"
1732+
16911733
async-each@^1.0.1:
16921734
version "1.0.3"
16931735
resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.3.tgz#b727dbf87d7651602f06f4d4ac387f47d91b0cbf"
@@ -2494,7 +2536,7 @@ consola@^1.4.5:
24942536
lodash "^4.17.5"
24952537
std-env "^1.1.0"
24962538

2497-
consola@^2.10.0, consola@^2.10.1, consola@^2.11.1, consola@^2.11.3, consola@^2.5.6, consola@^2.6.0, consola@^2.9.0:
2539+
consola@^2.10.0, consola@^2.10.1, consola@^2.11.0, consola@^2.11.1, consola@^2.11.3, consola@^2.5.6, consola@^2.6.0, consola@^2.9.0:
24982540
version "2.11.3"
24992541
resolved "https://registry.yarnpkg.com/consola/-/consola-2.11.3.tgz#f7315836224c143ac5094b47fd4c816c2cd1560e"
25002542
integrity sha512-aoW0YIIAmeftGR8GSpw6CGQluNdkWMWh3yEFjH/hmynTYnMtibXszii3lxCXmk8YxJtI3FAK5aTiquA5VH68Gw==
@@ -4441,6 +4483,11 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1:
44414483
dependencies:
44424484
is-extglob "^2.1.1"
44434485

4486+
is-https@^1.0.0:
4487+
version "1.0.0"
4488+
resolved "https://registry.yarnpkg.com/is-https/-/is-https-1.0.0.tgz#9c1dde000dc7e7288edb983bef379e498e7cb1bf"
4489+
integrity sha512-1adLLwZT9XEXjzhQhZxd75uxf0l+xI9uTSFaZeSESjL3E1eXSPpO+u5RcgqtzeZ1KCaNvtEwZSTO2P4U5erVqQ==
4490+
44444491
is-nan@^1.2.1:
44454492
version "1.3.0"
44464493
resolved "https://registry.yarnpkg.com/is-nan/-/is-nan-1.3.0.tgz#85d1f5482f7051c2019f5673ccebdb06f3b0db03"
@@ -4867,6 +4914,11 @@ lodash.toarray@^4.4.0:
48674914
resolved "https://registry.yarnpkg.com/lodash.toarray/-/lodash.toarray-4.4.0.tgz#24c4bfcd6b2fba38bfd0594db1179d8e9b656561"
48684915
integrity sha1-JMS/zWsvuji/0FlNsRedjptlZWE=
48694916

4917+
lodash.unionby@^4.8.0:
4918+
version "4.8.0"
4919+
resolved "https://registry.yarnpkg.com/lodash.unionby/-/lodash.unionby-4.8.0.tgz#883f098ff78f564a727b7508e09cdd539734bb83"
4920+
integrity sha1-iD8Jj/ePVkpye3UI4JzdU5c0u4M=
4921+
48704922
lodash.uniq@^4.5.0:
48714923
version "4.5.0"
48724924
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
@@ -4897,7 +4949,7 @@ lower-case@^1.1.1:
48974949
resolved "https://registry.yarnpkg.com/lower-case/-/lower-case-1.1.4.tgz#9a2cabd1b9e8e0ae993a4bf7d5875c39c42e8eac"
48984950
integrity sha1-miyr0bno4K6ZOkv31YdcOcQujqw=
48994951

4900-
lru-cache@^4.0.1, lru-cache@^4.1.2:
4952+
lru-cache@^4.0.0, lru-cache@^4.0.1, lru-cache@^4.1.2:
49014953
version "4.1.5"
49024954
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
49034955
integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==
@@ -7169,7 +7221,7 @@ sass-loader@^8.0.2:
71697221
schema-utils "^2.6.1"
71707222
semver "^6.3.0"
71717223

7172-
sax@>=0.6.0, sax@~1.2.4:
7224+
sax@>=0.6.0, sax@^1.2.4, sax@~1.2.4:
71737225
version "1.2.4"
71747226
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
71757227
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
@@ -7339,6 +7391,17 @@ simple-swizzle@^0.2.2:
73397391
dependencies:
73407392
is-arrayish "^0.3.1"
73417393

7394+
sitemap@^4.1.1:
7395+
version "4.1.1"
7396+
resolved "https://registry.yarnpkg.com/sitemap/-/sitemap-4.1.1.tgz#c9b459c7d797e629c61f56b86586d4f67dbf250b"
7397+
integrity sha512-+8yd66IxyIFEMFkFpVoPuoPwBvdiL7Ap/HS5YD7igqO4phkyTPFIprCAE9NMHehAY5ZGN3MkAze4lDrOAX3sVQ==
7398+
dependencies:
7399+
"@types/node" "^12.0.2"
7400+
"@types/sax" "^1.2.0"
7401+
arg "^4.1.1"
7402+
sax "^1.2.4"
7403+
xmlbuilder "^13.0.0"
7404+
73427405
snapdragon-node@^2.0.1:
73437406
version "2.1.1"
73447407
resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"
@@ -8621,6 +8684,11 @@ xml2js@^0.4.5:
86218684
sax ">=0.6.0"
86228685
xmlbuilder "~11.0.0"
86238686

8687+
xmlbuilder@^13.0.0:
8688+
version "13.0.2"
8689+
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-13.0.2.tgz#02ae33614b6a047d1c32b5389c1fdacb2bce47a7"
8690+
integrity sha512-Eux0i2QdDYKbdbA6AM6xE4m6ZTZr4G4xF9kahI2ukSEMCzwce2eX9WlTI5J3s+NU7hpasFsr8hWIONae7LluAQ==
8691+
86248692
xmlbuilder@~11.0.0:
86258693
version "11.0.1"
86268694
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3"

0 commit comments

Comments
 (0)