Skip to content

Commit 8159890

Browse files
authored
chore(docs): add generated robots.txt and sitemap.xml for SEO (#5257)
Co-authored-by: Jacob Müller
1 parent d9a9672 commit 8159890

File tree

3 files changed

+107
-9
lines changed

3 files changed

+107
-9
lines changed

docs/nuxt.config.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ const RX_CODE_FILENAME = /^\/\/ ([\w,\s-]+\.[A-Za-z]{1,4})\n/m
2121

2222
const ANCHOR_LINK_HEADING_LEVELS = [2, 3, 4, 5]
2323

24+
// Determine if documentation generation is published production docs
25+
// Must be from 'bootstrap-vue/bootstrap-vue' repo 'master' branch
26+
const IS_PROD_DOCS =
27+
process.env.VERCEL_GITHUB_ORG === 'bootstrap-vue' &&
28+
process.env.VERCEL_GITHUB_REPO === 'bootstrap-vue' &&
29+
process.env.VERCEL_GITHUB_COMMIT_REF === 'master'
30+
2431
// --- Utility methods ---
2532

2633
// Get routes by a given dir
@@ -154,17 +161,17 @@ module.exports = {
154161
// ENV vars provided by Vercel/Zeit Now build
155162
// https://zeit.co/docs/v2/build-step#system-environment-variables
156163
// - `true` if on Zeit Now (dev or PR)
157-
VERCEL_NOW: process.env.VERCEL_GITHUB_DEPLOYMENT || process.env.NOW_GITHUB_DEPLOYMENT,
164+
VERCEL_NOW: process.env.VERCEL_GITHUB_DEPLOYMENT,
158165
// - The branch name used for the deploy (i.e. `dev`, `master`, `patch-1`, etc)
159-
VERCEL_BRANCH: process.env.VERCEL_GITHUB_COMMIT_REF || process.env.NOW_GITHUB_COMMIT_REF,
166+
VERCEL_BRANCH: process.env.VERCEL_GITHUB_COMMIT_REF,
160167
// - The Commit SHA hash
161-
VERCEL_COMMIT_SHA: process.env.VERCEL_GITHUB_COMMIT_SHA || process.env.NOW_GITHUB_COMMIT_SHA,
168+
VERCEL_COMMIT_SHA: process.env.VERCEL_GITHUB_COMMIT_SHA,
162169
// - The deployment URL
163-
VERCEL_URL: process.env.VERCEL_URL || process.env.NOW_URL,
170+
VERCEL_URL: process.env.VERCEL_URL,
164171
// - The Github Organization (ie. bootstrap-vue)
165-
VERCEL_GITHUB_ORG: process.env.VERCEL_GITHUB_ORG || process.env.NOW_GITHUB_ORG,
172+
VERCEL_GITHUB_ORG: process.env.VERCEL_GITHUB_ORG,
166173
// - The repo is the organization (i.e. bootstrap-vue)
167-
VERCEL_GITHUB_REPO: process.env.VERCEL_GITHUB_REPO || process.env.NOW_GITHUB_REPO
174+
VERCEL_GITHUB_REPO: process.env.VERCEL_GITHUB_REPO
168175
},
169176

170177
build: {
@@ -269,7 +276,7 @@ module.exports = {
269276
plugins: ['~/plugins/bootstrap-vue.js', '~/plugins/play.js', '~/plugins/docs.js'],
270277

271278
buildModules: ['@nuxtjs/google-analytics'],
272-
modules: ['@nuxtjs/pwa'],
279+
modules: ['@nuxtjs/pwa', '@nuxtjs/robots', '@nuxtjs/sitemap'],
273280

274281
'google-analytics': {
275282
id: GA_TRACKING_ID,
@@ -278,6 +285,25 @@ module.exports = {
278285
}
279286
},
280287

288+
// We enable crawling in production docs only
289+
robots: () => {
290+
// In production docs we allow crawling, else we deny crawling
291+
return [IS_PROD_DOCS ? { UserAgent: '*', Allow: '/' } : { UserAgent: '*', Disallow: '/' }]
292+
},
293+
294+
// We only include a populated `sitemap.xml` in production docs
295+
sitemap: {
296+
// Sitemaps requires a hostname, so we use localhost in
297+
// non-prod mode just to make the sitemap module happy
298+
hostname: IS_PROD_DOCS ? BASE_URL : 'http://localhost',
299+
// Exclude all static routes when not prod
300+
// Exclude only redirect routes in prod
301+
exclude: IS_PROD_DOCS ? ['/docs/misc', '/docs/misc/**', '/docs/layout'] : ['/', '/**'],
302+
// Include dynamic slug routes (from `generate.routes`) in prod, while
303+
// in non-prod docs we do not include dynamic routes (empty array)
304+
...(IS_PROD_DOCS ? {} : { routes: [] })
305+
},
306+
281307
head: {
282308
meta: [{ 'http-equiv': 'X-UA-Compatible', content: 'IE=edge' }],
283309
script: [

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105
"@babel/standalone": "^7.9.5",
106106
"@nuxtjs/google-analytics": "^2.2.3",
107107
"@nuxtjs/pwa": "^3.0.0-beta.20",
108+
"@nuxtjs/robots": "^2.4.2",
109+
"@nuxtjs/sitemap": "^2.2.1",
108110
"@vue/test-utils": "1.0.0-beta.29",
109111
"autoprefixer": "^9.7.6",
110112
"babel-core": "^7.0.0-bridge.0",

yarn.lock

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,26 @@
15181518
jimp-compact "^0.8.0"
15191519
workbox-cdn "^4.3.1"
15201520

1521+
"@nuxtjs/robots@^2.4.2":
1522+
version "2.4.2"
1523+
resolved "https://registry.yarnpkg.com/@nuxtjs/robots/-/robots-2.4.2.tgz#9a96c91abb70e39b414eec502ef1cf7d5ef0235e"
1524+
integrity sha512-BW3qhvxlPBKlMkZHtARFPeliFraiZHS28G3j4qgRbSfOBtHC0yDX3Dnq1LkQMzAbPfbw6A1L3sdjgBVZZnfFAw==
1525+
1526+
"@nuxtjs/sitemap@^2.2.1":
1527+
version "2.2.1"
1528+
resolved "https://registry.yarnpkg.com/@nuxtjs/sitemap/-/sitemap-2.2.1.tgz#a00b528e361673b3f2651a0f1ee4081e89f9c6fd"
1529+
integrity sha512-GrXTueBaSQgAuBbUrGcKu37VbZBOZ4omHqk8FfthK71R26vp9LWUcqlRbuQaIrAYynjSfSPxaLpX8opUwO1nKw==
1530+
dependencies:
1531+
async-cache "^1.1.0"
1532+
consola "^2.11.3"
1533+
etag "^1.8.1"
1534+
fresh "^0.5.2"
1535+
fs-extra "^8.1.0"
1536+
is-https "^1.0.0"
1537+
lodash.unionby "^4.8.0"
1538+
minimatch "^3.0.4"
1539+
sitemap "^4.1.1"
1540+
15211541
"@nuxtjs/youch@^4.2.3":
15221542
version "4.2.3"
15231543
resolved "https://registry.yarnpkg.com/@nuxtjs/youch/-/youch-4.2.3.tgz#36f8b22df5a0efaa81373109851e1d857aca6bed"
@@ -1633,6 +1653,11 @@
16331653
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.11.0.tgz#390ea202539c61c8fa6ba4428b57e05bc36dc47b"
16341654
integrity sha512-uM4mnmsIIPK/yeO+42F2RQhGUIs39K2RFmugcJANppXe6J1nvH87PvzPZYpza7Xhhs8Yn9yIAVdLZ84z61+0xQ==
16351655

1656+
"@types/node@^12.0.2":
1657+
version "12.12.37"
1658+
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.37.tgz#cb4782d847f801fa58316da5b4801ca3a59ae790"
1659+
integrity sha512-4mXKoDptrXAwZErQHrLzpe0FN/0Wmf5JRniSVIdwUrtDf9wnmEV1teCNLBo/TwuXhkK/bVegoEn/wmb+x0AuPg==
1660+
16361661
"@types/normalize-package-data@^2.4.0":
16371662
version "2.4.0"
16381663
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
@@ -1660,6 +1685,13 @@
16601685
dependencies:
16611686
"@types/node" "*"
16621687

1688+
"@types/sax@^1.2.0":
1689+
version "1.2.1"
1690+
resolved "https://registry.yarnpkg.com/@types/sax/-/sax-1.2.1.tgz#e0248be936ece791a82db1a57f3fb5f7c87e8172"
1691+
integrity sha512-dqYdvN7Sbw8QT/0Ci5rhjE4/iCMJEM0Y9rHpCu+gGXD9Lwbz28t6HI2yegsB6BoV1sShRMU6lAmAcgRjmFy7LA==
1692+
dependencies:
1693+
"@types/node" "*"
1694+
16631695
"@types/stack-utils@^1.0.1":
16641696
version "1.0.1"
16651697
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
@@ -2185,6 +2217,11 @@ are-we-there-yet@~1.1.2:
21852217
delegates "^1.0.0"
21862218
readable-stream "^2.0.6"
21872219

2220+
arg@^4.1.1:
2221+
version "4.1.3"
2222+
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
2223+
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
2224+
21882225
argparse@^1.0.7:
21892226
version "1.0.10"
21902227
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
@@ -2320,6 +2357,13 @@ astral-regex@^1.0.0:
23202357
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
23212358
integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==
23222359

2360+
async-cache@^1.1.0:
2361+
version "1.1.0"
2362+
resolved "https://registry.yarnpkg.com/async-cache/-/async-cache-1.1.0.tgz#4a9a5a89d065ec5d8e5254bd9ee96ba76c532b5a"
2363+
integrity sha1-SppaidBl7F2OUlS9nulrp2xTK1o=
2364+
dependencies:
2365+
lru-cache "^4.0.0"
2366+
23232367
async-each@^1.0.1:
23242368
version "1.0.3"
23252369
resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.3.tgz#b727dbf87d7651602f06f4d4ac387f47d91b0cbf"
@@ -6938,6 +6982,11 @@ is-hexadecimal@^1.0.0:
69386982
resolved "https://registry.yarnpkg.com/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz#cc35c97588da4bd49a8eedd6bc4082d44dcb23a7"
69396983
integrity sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw==
69406984

6985+
is-https@^1.0.0:
6986+
version "1.0.0"
6987+
resolved "https://registry.yarnpkg.com/is-https/-/is-https-1.0.0.tgz#9c1dde000dc7e7288edb983bef379e498e7cb1bf"
6988+
integrity sha512-1adLLwZT9XEXjzhQhZxd75uxf0l+xI9uTSFaZeSESjL3E1eXSPpO+u5RcgqtzeZ1KCaNvtEwZSTO2P4U5erVqQ==
6989+
69416990
is-installed-globally@^0.1.0:
69426991
version "0.1.0"
69436992
resolved "https://registry.yarnpkg.com/is-installed-globally/-/is-installed-globally-0.1.0.tgz#0dfd98f5a9111716dd535dda6492f67bf3d25a80"
@@ -8166,6 +8215,11 @@ lodash.templatesettings@^4.0.0:
81668215
dependencies:
81678216
lodash._reinterpolate "^3.0.0"
81688217

8218+
lodash.unionby@^4.8.0:
8219+
version "4.8.0"
8220+
resolved "https://registry.yarnpkg.com/lodash.unionby/-/lodash.unionby-4.8.0.tgz#883f098ff78f564a727b7508e09cdd539734bb83"
8221+
integrity sha1-iD8Jj/ePVkpye3UI4JzdU5c0u4M=
8222+
81698223
lodash.uniq@^4.5.0:
81708224
version "4.5.0"
81718225
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
@@ -8245,7 +8299,7 @@ lowercase-keys@^1.0.0:
82458299
resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-1.0.1.tgz#6f9e30b47084d971a7c820ff15a6c5167b74c26f"
82468300
integrity sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==
82478301

8248-
lru-cache@^4.0.1, lru-cache@^4.1.1, lru-cache@^4.1.2, lru-cache@^4.1.5:
8302+
lru-cache@^4.0.0, lru-cache@^4.0.1, lru-cache@^4.1.1, lru-cache@^4.1.2, lru-cache@^4.1.5:
82498303
version "4.1.5"
82508304
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
82518305
integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==
@@ -11295,7 +11349,7 @@ sass-loader@^8.0.2:
1129511349
schema-utils "^2.6.1"
1129611350
semver "^6.3.0"
1129711351

11298-
sax@~1.2.4:
11352+
sax@^1.2.4, sax@~1.2.4:
1129911353
version "1.2.4"
1130011354
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
1130111355
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
@@ -11528,6 +11582,17 @@ sisteransi@^1.0.4:
1152811582
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
1152911583
integrity sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==
1153011584

11585+
sitemap@^4.1.1:
11586+
version "4.1.1"
11587+
resolved "https://registry.yarnpkg.com/sitemap/-/sitemap-4.1.1.tgz#c9b459c7d797e629c61f56b86586d4f67dbf250b"
11588+
integrity sha512-+8yd66IxyIFEMFkFpVoPuoPwBvdiL7Ap/HS5YD7igqO4phkyTPFIprCAE9NMHehAY5ZGN3MkAze4lDrOAX3sVQ==
11589+
dependencies:
11590+
"@types/node" "^12.0.2"
11591+
"@types/sax" "^1.2.0"
11592+
arg "^4.1.1"
11593+
sax "^1.2.4"
11594+
xmlbuilder "^13.0.0"
11595+
1153111596
slash@^2.0.0:
1153211597
version "2.0.0"
1153311598
resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44"
@@ -13461,6 +13526,11 @@ xml-name-validator@^3.0.0:
1346113526
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"
1346213527
integrity sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==
1346313528

13529+
xmlbuilder@^13.0.0:
13530+
version "13.0.2"
13531+
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-13.0.2.tgz#02ae33614b6a047d1c32b5389c1fdacb2bce47a7"
13532+
integrity sha512-Eux0i2QdDYKbdbA6AM6xE4m6ZTZr4G4xF9kahI2ukSEMCzwce2eX9WlTI5J3s+NU7hpasFsr8hWIONae7LluAQ==
13533+
1346413534
xmlchars@^2.1.1:
1346513535
version "2.2.0"
1346613536
resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"

0 commit comments

Comments
 (0)