Skip to content

Commit be76894

Browse files
authored
Respec fix and SEO changes (#2603)
* fix: v2.0 maintainers and version/date Signed-off-by: Mike Ralphson <[email protected]> * Add some largely non-visible SEO improvements to the rendered spec Signed-off-by: Mike Ralphson <[email protected]>
1 parent 347f361 commit be76894

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

.github/workflows/respec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222

2323
steps:
2424
- uses: actions/checkout@v2 # checkout main branch
25+
with:
26+
fetch-depth: 0
2527

2628
- name: Install dependencies
2729
run: npm i

scripts/md2html/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ cp -p markdown/* ../../deploy/ 2> /dev/null
1414
node md2html.js --respec --maintainers ./history/MAINTAINERS_v2.0.md ../../versions/2.0.md > ../../deploy/oas/v2.0.html
1515

1616
latest=`git describe --abbrev=0 --tags`
17+
latestCopied=none
1718
for filename in ../../versions/[3456789].*.md ; do
1819
version=$(basename "$filename" .md)
1920
node md2html.js --respec --maintainers ../../MAINTAINERS.md ${filename} > ../../deploy/oas/v$version.html
2021
if [ $version = $latest ]; then
2122
if [[ ${version} != *"rc"* ]];then
2223
# version is not a Release Candidate
2324
cp -p ../../deploy/oas/v$version.html ../../deploy/oas/latest.html
25+
latestCopied=v$version
2426
fi
2527
fi
2628
done
29+
echo Latest tag is $latest, copied $latestCopied to latest.html
2730

scripts/md2html/md2html.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
/* bikeshed claims to support markdown syntax, but not (yet) commonmark.
2-
ReSpec supports markdown formatting, but this shows up on the page before being rendered
1+
/* ReSpec supports markdown formatting, but this shows up on the page before being rendered
32
Hence we render the markdown to HTML ourselves, this gives us
4-
complete control over formatting and syntax highlighting (where
5-
highlight.js does a better job than bikeshed's Pygments) */
3+
complete control over formatting and syntax highlighting */
64

75
'use strict';
86

@@ -19,9 +17,6 @@ const hljs = require('highlight.js');
1917
const cheerio = require('cheerio');
2018

2119
let argv = require('yargs')
22-
.boolean('bikeshed')
23-
.alias('b','bikeshed')
24-
.describe('bikeshed','Output in bikeshed format')
2520
.boolean('respec')
2621
.alias('r','respec')
2722
.describe('respec','Output in respec format')
@@ -72,6 +67,11 @@ function preface(title,options) {
7267
};
7368

7469
let preface = `<html lang="en"><head><meta charset="UTF-8"><title>${md.utils.escapeHtml(title)}</title>`;
70+
71+
// SEO
72+
preface += '<meta name="description" content="The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.">';
73+
preface += '<link rel="canonical" href="https://spec.openapis.org/oas/latest.html" />';
74+
7575
if (options.respec) {
7676
preface += '<script src="https://spec.openapis.org/js/respec-oai.js" class="remove"></script>';
7777
preface += `<script class="remove">var respecConfig = ${JSON.stringify(respec)};</script>`;
@@ -91,7 +91,7 @@ function preface(title,options) {
9191
preface += fs.readFileSync(path.resolve(__dirname,'gist.css'),'utf8').split('\n').join(' ');
9292
preface += '</style>';
9393
preface += '<section id="abstract">';
94-
preface += 'The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for REST APIs, which allows both humans and computers to discover and understand the capabilities of a service without requiring access to source code, additional documentation, or inspection of network traffic. When properly defined via OpenAPI, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interface descriptions have done for lower-level programming, the OpenAPI Specification removes guesswork in calling a service.';
94+
preface += 'The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs, which allows both humans and computers to discover and understand the capabilities of a service without requiring access to source code, additional documentation, or inspection of network traffic. When properly defined via OpenAPI, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interface descriptions have done for lower-level programming, the OpenAPI Specification removes guesswork in calling a service.';
9595
preface += '</section>';
9696
preface += '<section class="notoc" id="sotd">';
9797
preface += '<h2>Status of This Document</h2>';
@@ -121,15 +121,24 @@ function doMaintainers() {
121121
}
122122

123123
function getPublishDate(m) {
124+
let result = new Date();
124125
let h = md.render(m);
125126
let $ = cheerio.load(h);
126-
let t = $('tbody').last();
127-
let c = $(t).children('tr').children('td');
128-
let v = $(c[0]).text();
129-
let d = $(c[1]).text();
130-
argv.subtitle = v;
131-
if (d === 'TBA') return new Date();
132-
return new Date(d);
127+
$('table').each(function(i,table){
128+
const h = $(table).find('th');
129+
const headers = [];
130+
$(h).each(function(i,header){
131+
headers.push($(header).text());
132+
});
133+
if (headers.length >= 2 && headers[0] === 'Version' && headers[1] === 'Date') {
134+
let c = $(table).find('tr').find('td');
135+
let v = $(c[0]).text();
136+
let d = $(c[1]).text();
137+
argv.subtitle = v;
138+
if (d !== 'TBA') result = new Date(d);
139+
}
140+
});
141+
return result;
133142
}
134143

135144
if (argv.maintainers) {
@@ -178,8 +187,6 @@ for (let l in lines) {
178187
let originalIndent = indent;
179188

180189
let prevIndent = indents[indents.length-1]; // peek
181-
182-
/* bikeshed is a bit of a pita when it comes to header nesting */
183190
let delta = indent-prevIndent;
184191

185192
if (!argv.respec) {
@@ -301,7 +308,7 @@ for (let l in lines) {
301308
lines[l] = line;
302309
}
303310

304-
s = preface('OpenAPI Specification',argv)+'\n\n'+lines.join('\n');
311+
s = preface(`OpenAPI Specification v${argv.subtitle} | Introduction, Definitions, & More`,argv)+'\n\n'+lines.join('\n');
305312
let out = md.render(s);
306313
out = out.replace(/\[([RGB])\]/g,function(match,group1){
307314
console.warn('Fixing',match,group1);

0 commit comments

Comments
 (0)