Skip to content

Commit 6c42899

Browse files
committed
Link to learn site for examples
For now directly to the yaml, later to the html page
1 parent 74323af commit 6c42899

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

scripts/md2html/md2html.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,16 @@ for (let l in lines) {
270270
}
271271

272272
// fix relative links (to examples)
273-
//TODO: adjust when moving examples to a different repo
274-
if (!inCodeBlock && line.indexOf('](../') >= 0) {
273+
if (!inCodeBlock && line.indexOf('](../examples/') >= 0) {
274+
line = line.replace(/\(\.\.\/examples\/([^)]+)\)/g,function(match,group1){
275+
//TODO: group1 = group1.replace('.yaml','.html');
276+
return `(https://learn.openapis.org/examples/${group1})`;
277+
})
278+
} else if (!inCodeBlock && line.indexOf('](../') >= 0) {
275279
const regExp = /\((\.\.[^)]+)\)/g;
276280
line = line.replace(regExp,function(match,group1){
277281
console.warn('Fixing relative link',group1,line);
278-
return '('+url.resolve('https://github.com/OAI/OpenAPI-Specification/tree/master/versions/foo',group1)+')';
282+
return '('+url.resolve('https://github.com/OAI/OpenAPI-Specification/tree/main/versions/foo',group1)+')';
279283
});
280284
}
281285

tests/md2html/fixtures/basic-new.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
<p>Definition of Foo.</p>
1111
</section></section><section><h1>Another Heading 2</h1>
1212
<p>Text for second section</p>
13-
<p><a href="https://github.com/OAI/OpenAPI-Specification/tree/master/examples/foo.yaml">Relative link</a></p>
13+
<p><a href="https://learn.openapis.org/examples/foo.yaml">Relative link to example</a></p>
14+
<p><a href="https://github.com/OAI/OpenAPI-Specification/tree/main/something/else">Relative link to something else</a></p>
1415
<section><h2>Heading 3</h2>
1516
<p>Text for first subsection</p>
1617
<p>[[RFC3986]]</p>

tests/md2html/fixtures/basic-new.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ Definition of Foo.
2020

2121
Text for second section
2222

23-
[Relative link](../examples/foo.yaml)
23+
[Relative link to example](../examples/foo.yaml)
24+
25+
[Relative link to something else](../something/else)
2426

2527
### Heading 3
2628

0 commit comments

Comments
 (0)