Skip to content

Commit ebc8ce6

Browse files
Validate docs have a title: and fix for astro migration (microsoft#2561)
Astro requires every doc to have a title. Adding a simple script to validate that so we don't have to patch things when migrating.
1 parent 950ff22 commit ebc8ce6

File tree

11 files changed

+94
-9
lines changed

11 files changed

+94
-9
lines changed

docs/extending-typespec/diagnostics.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Diagnostics
1+
---
2+
title: Diagnostics
3+
---
24

35
TypeSpec compiler report errors and warnings in the spec using the diagnostic API.
46

docs/getting-started/getting-started-http.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Getting Started with TypeSpec For Http
1+
---
2+
title: Getting Started with TypeSpec For Http
3+
---
24

35
Let's create a REST API definition with TypeSpec. TypeSpec has an official HTTP API "binding" called `@typespec/http`. It's a set of TypeSpec declarations and decorators that describe HTTP APIs and can be used by code generators to generate OpenAPI descriptions, implementation code, and the like.
46
Built on top of the http library there is the rest library `@typespec/rest` which provide some REST concept like resources.

docs/introduction/editor/vs.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# TypeSpec Visual Studio Extension
1+
---
2+
title: TypeSpec Visual Studio Extension
3+
---
24

35
## Installation
46

docs/introduction/editor/vscode.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# TypeSpec VSCode extension
1+
---
2+
title: TypeSpec VSCode extension
3+
---
24

35
## Installation
46

docs/introduction/reproducibility.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Reproducibility
1+
---
2+
title: Reproducibility
3+
---
24

35
A key point to service definition is the ability to reliably reproduce the exact same output over time. In cases like:
46

docs/release-notes/cadl-typespec-migration.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Cadl to TypeSpec rename completed in March 2023 release
1+
---
2+
title: Cadl to TypeSpec rename completed in March 2023 release
3+
---
24

35
As you may recall from our previous email to partners, we are renaming the product as it becomes more mature, stable and one step closer to release.
46

docs/standard-library/discriminated-types.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Discriminated types
1+
---
2+
title: Discriminated types
3+
---
24

35
TypeSpec can express unions and inheritance. However, when sending types over the wire many languages need a way to discriminate between the various union variants or models in an inheritance hierarchy.
46

docs/standard-library/http/content-types.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Content types
1+
---
2+
title: Content types
3+
---
24

35
## Default behavior
46

docs/standard-library/http/encoding.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Encoding of types
1+
---
2+
title: Encoding of types
3+
---
24

35
This document describe how the http library interpret TypeSpec built-in types and how to configure
46

eng/pipelines/jobs/build-and-test.yml

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ steps:
2727
- script: node eng/scripts/check-for-changed-files.js
2828
displayName: Check Git Status For Changed Files
2929

30+
- script: node eng/scripts/check-docs.js
31+
displayName: Check docs
32+
condition: ne(variables['Agent.OS'], 'Windows_NT')
33+
3034
- script: node common/scripts/install-run-rush.js cspell
3135
displayName: Spell check
3236
condition: ne(variables['Agent.OS'], 'Windows_NT')

eng/scripts/check-docs.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// @ts-check
2+
3+
// cspell:ignore astro
4+
// This script check the docs are compatible for astro to simplify migration
5+
// It check each docs has
6+
// - a `title:` frontmatter
7+
import { readFile, readdir } from "fs/promises";
8+
import { resolve } from "path";
9+
import { repoRoot } from "./helpers.js";
10+
11+
const docsFolder = resolve(repoRoot, "docs");
12+
13+
async function findMarkdownFiles(folder) {
14+
const items = await readdir(folder, { withFileTypes: true });
15+
16+
return (
17+
await Promise.all(
18+
items.map(async (item) => {
19+
if (item.isDirectory()) {
20+
const files = await findMarkdownFiles(resolve(folder, item.name));
21+
return files.map((x) => resolve(folder, x));
22+
}
23+
24+
if (item.name.endsWith(".md")) {
25+
return [resolve(folder, item.name)];
26+
} else {
27+
return [];
28+
}
29+
})
30+
)
31+
).flat();
32+
}
33+
await main();
34+
35+
async function main() {
36+
const docs = await findMarkdownFiles(docsFolder);
37+
38+
const failure = [];
39+
const regex = /^---.*title:.*---$/ms;
40+
for (const doc of docs) {
41+
const buffer = await readFile(doc, { encoding: "utf-8" });
42+
const content = buffer.toString();
43+
if (!regex.test(content)) {
44+
failure.push(doc);
45+
}
46+
}
47+
48+
if (failure.length > 0) {
49+
console.log("Files with missing title: frontmatter", failure);
50+
51+
console.log(
52+
[
53+
"Make sure to add front matter in the file with title, e.g.:",
54+
"---",
55+
"title: xyz",
56+
"---",
57+
].join("\n")
58+
);
59+
process.exit(1);
60+
} else {
61+
console.log("Docs look good!");
62+
}
63+
}

0 commit comments

Comments
 (0)