Skip to content

Commit

Permalink
Fix external links
Browse files Browse the repository at this point in the history
  • Loading branch information
xingrz committed Jan 14, 2022
1 parent fd7efe6 commit 80bd697
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ jobs:
- name: Upload HTML
uses: actions/upload-artifact@v2
with:
name: keywords
path: keywords
name: yaml
path: yaml

build:
needs: source
Expand All @@ -52,12 +52,12 @@ jobs:
- name: Download HTML
uses: actions/download-artifact@v2
with:
name: keywords
path: keywords
name: yaml
path: yaml

- name: Build docset
run: |
dashing build --source keywords
dashing build --source yaml
mkdir -p docset
mv gitlab-ci.docset docset/
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DS_Store
node_modules

/keywords
/yaml
/VERSION
/DIGEST

Expand Down
15 changes: 6 additions & 9 deletions fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ const { join, basename } = require('path');
const { outputFile } = require('fs-extra');
const { createHash } = require('crypto');

const BASE = 'https://docs.gitlab.com/';
const URL = `${BASE}/ee/ci/yaml/index.html`;

const OUT_DIR = join(__dirname, 'keywords');
const DOC_URL = `https://docs.gitlab.com/ee/ci/yaml/index.html`;
const OUT_DIR = join(__dirname, 'yaml');

(async () => {
console.log('Loading document...');
const $ = cheerio.load(await http.get(URL).text());
const $ = cheerio.load(await http.get(DOC_URL).text());

const dropdown = $('#navbarDropdown').text().match(/GitLab\.com \(([^\)]+)\)/);
const version = dropdown[1];
Expand All @@ -24,7 +22,7 @@ const OUT_DIR = join(__dirname, 'keywords');
continue;
}
if (href.attribs.href.startsWith('/assets/')) {
const asset = await http.get(`${BASE}${href.attribs.href}`).text();
const asset = await http.get(new URL(href.attribs.href, DOC_URL)).text();
const name = basename(href.attribs.href).replace(/#.*$/, '');
await outputFile(join(OUT_DIR, 'assets', name), asset);
href.attribs.href = `assets/${name}`;
Expand All @@ -40,9 +38,8 @@ const OUT_DIR = join(__dirname, 'keywords');
console.log('Rebuilding links...');
const as = $('a[href]');
for (const a of as) {
const { href } = a.attribs;
if (!href.startsWith('http://') && !href.startsWith('https://')) {
a.attribs.href = `${BASE}${href}`;
if (!a.attribs.href.startsWith('#')) {
a.attribs.href = new URL(a.attribs.href, DOC_URL).toString();
}
}

Expand Down

0 comments on commit 80bd697

Please sign in to comment.