Skip to content

Commit

Permalink
Fix anchor doc links
Browse files Browse the repository at this point in the history
  • Loading branch information
flekschas committed Oct 4, 2017
1 parent e79268f commit 9ed98d7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
14 changes: 9 additions & 5 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ if (production) {
// Extend marked options
const renderer = new marked.marked.Renderer();

//
const anchorPrefix = ghp ? '' : '/docs/';
const anchorLinkPrefix = ghp ? '/docs/#' : '#/docs/';

const makeH = (increment = 0) => (text, level) => {
const escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');

return `
<h${level + increment} id="/docs/${escapedText}" class="underlined anchored">
<a href="#/docs/${escapedText}" class="hidden-anchor">
<h${level + increment} id="${anchorPrefix}${escapedText}" class="underlined anchored">
<a href="${anchorLinkPrefix}${escapedText}" class="hidden-anchor">
<svg-icon icon-id="link"></svg-icon>
</a>
<span>${text}</span>
Expand Down Expand Up @@ -254,7 +258,7 @@ gulp.task('sidebar', () => gulp
(a, b) => `href="${b.toLowerCase().replace('#', '/')}"`
);
contents = contents.replace(/href="home/gi, 'href="getting-started');
contents = contents.replace(/href="/gi, 'href="#/docs/');
contents = contents.replace(/href="/gi, `href="${anchorLinkPrefix}`);

return contents;
}
Expand Down Expand Up @@ -283,8 +287,8 @@ gulp.task('wiki', () => gulp
const prefix = fileName.toLowerCase().replace(/ /gi, '-');

// Add page-specific prefices to anchor links
contents = contents.replace(/id="\/docs\//gi, `id="/docs/${prefix}/`);
contents = contents.replace(/href="#\/docs\//gi, `href="#/docs/${prefix}/`);
contents = contents.replace(/id="\/docs\//gi, `id="${anchorPrefix}${prefix}/`);
contents = contents.replace(/href="#\/docs\//gi, `href="${anchorLinkPrefix}${prefix}/`);

return `${makeH(0)(fileName, 1)}\n${contents}`;
}
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hipiler",
"description": "Visual exploration of large genome interaction matrices with interactive small multiples.",
"author": "Fritz Lekschas (http://lekschas.de)",
"version": "1.1.1",
"version": "1.1.2",
"repository": {
"type": "git",
"url": "https://github.com/flekschas/hipiler.git"
Expand Down Expand Up @@ -89,9 +89,10 @@
},
"scripts": {
"build": "npm run update && gulp clean && gulp && au build --env prod && gulp index",
"ghp": "npm run update && gulp clean && gulp clean-dist && gulp && au build --env prod && gulp ghp && scripts/cp-prod.sh hipiler-ghp",
"ghp": "npm run update && gulp clean && gulp clean-dist && gulp --ghp && au build --env prod && gulp ghp && scripts/cp-prod.sh hipiler-ghp",
"start": "gulp && au run --watch",
"test": "gulp && au test",
"update": "git pull && git submodule update --init --recursive --remote --merge && npm install && gulp"
"update": "git pull && git submodule update --init --recursive --remote --merge && npm install && gulp",
"hurz": "gulp --ghp"
}
}
1 change: 1 addition & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export default class App {

if (window.hipilerConfig.ghp) {
config.options.pushState = true;
config.options.hashChange = false;
config.options.root = '/';
}

Expand Down

0 comments on commit 9ed98d7

Please sign in to comment.