Skip to content

Commit 487d252

Browse files
Improve search-engine crawlability of docs (#719)
1 parent ef25584 commit 487d252

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

.vitepress/config.mjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export default defineConfig({
1212
description: "MAVLink Developer Guide",
1313
//base: process.env.BRANCH_NAME ? "/" + process.env.BRANCH_NAME + "/" : "", //Build doesn't use branches!
1414
base: "",
15+
lastUpdated: true,
16+
sitemap: {
17+
hostname: "https://mavlink.io",
18+
},
1519
srcExclude: [
1620
"de/**/*.md",
1721
"ja/**/*.md",
@@ -115,8 +119,36 @@ export default defineConfig({
115119
},
116120
},
117121
//Logs every page loaded on build. Good way to catch errors not caught by other things.
122+
//Also injects per-page SEO metadata (description, OpenGraph, canonical) into the
123+
//server-rendered <head> so message pages are better crawled/snippeted by search engines.
118124
async transformPageData(pageData, { siteConfig }) {
119125
console.log(pageData.filePath);
126+
127+
const desc =
128+
pageData.frontmatter.description ||
129+
pageData.description ||
130+
(pageData.title
131+
? `${pageData.title} — MAVLink message, enum and command reference.`
132+
: "MAVLink Developer Guide");
133+
134+
// Set pageData.description so VitePress's own <meta name="description"> uses it
135+
// (pushing a second description tag in head would be deduped in favour of the default).
136+
pageData.description = desc;
137+
138+
const url =
139+
"https://mavlink.io/" +
140+
pageData.relativePath
141+
.replace(/(^|\/)index\.md$/, "$1")
142+
.replace(/\.md$/, ".html");
143+
144+
pageData.frontmatter.head ??= [];
145+
pageData.frontmatter.head.push(
146+
["meta", { property: "og:title", content: pageData.title }],
147+
["meta", { property: "og:description", content: desc }],
148+
["meta", { property: "og:type", content: "article" }],
149+
["meta", { property: "og:url", content: url }],
150+
["link", { rel: "canonical", href: url }]
151+
);
120152
},
121153

122154
//

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"docs:buildwin": "set NODE_OPTIONS=--max_old_space_size=8192 && vitepress build .",
1010
"docs:build_ubuntu": "NODE_OPTIONS='--max-old-space-size=8192' vitepress build .",
1111
"docs:preview": "vitepress preview .",
12-
"docs:sitemap": "python3 ./scripts/gen_sitemap.py",
1312
"docs:gen_alt_sidebar_ubuntu": "python3 ./scripts/gen_alt_sidebar.py",
1413
"docs:get_alt_sidebar_windows": "python ./scripts/gen_alt_sidebar.py",
1514
"start": "yarn docs:dev",

public/robots.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
User-agent: *
2+
3+
Sitemap: https://mavlink.io/sitemap.xml

0 commit comments

Comments
 (0)