Skip to content

Commit

Permalink
fix article links
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Feb 16, 2024
1 parent bf1a5dd commit a159a5c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
10 changes: 8 additions & 2 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,13 @@ const Builder = function(outBaseDir, options) {
}

function isRelative(url) {
return !url.startsWith('#') && !url.startsWith('/') && !url.includes('://');
return !url.startsWith('#') &&
!url.startsWith('/') &&
!url.includes('://');
}

function isArticleLink(url) {
return !url.includes('/') && url.endsWith('.html');
}

// Try top fix relative links. This *should* only
Expand All @@ -543,7 +549,7 @@ const Builder = function(outBaseDir, options) {
//const basedir = path.dirname(contentFileName);
// console.log('---> pageUrl:', pageUrl);
function fixRelLink(m, prefix, url, suffix) {
if (isSameDomain(url, pageUrl) && isRelative(url)) {
if (isSameDomain(url, pageUrl) && isRelative(url) && !isArticleLink(url)) {
// a link that starts with "../" should be "../../" if it's in a translation
// a link that starts with "resources" should be "../resources" if it's in a translation
//const testName = path.join(basedir, url);
Expand Down
6 changes: 5 additions & 1 deletion test/expected/test/lessons/ja/test-one.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@
<h1>Article One</h1>
<div class="lesson-main">
<p>This is a <span>foo <em>bar</em> foo</span> test
and another <div>foo <em>bar</em> foo</div> grr.</p>
and another <div>foo <em>bar</em> foo</div> grr.
Link to <a href="article.html">another article</a>.
Link to <a href="/absoute-article.html">absolute article</a>.
Link to <a href="../../resource/back.jpg">back resource</a>.
Link to <a href="../resource/forward.jpg">forward resource</a>.</p>
<pre class="prettyprint notranslate" translate="no"><code class="lang-html">&lt;div&gt;test *abc*&lt;div&gt;
</code></pre>
<img src="../resources/foo.jpg">
Expand Down
6 changes: 5 additions & 1 deletion test/expected/test/lessons/test-one.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@
<h1>Article One</h1>
<div class="lesson-main">
<p>This is a <span>foo <em>bar</em> foo</span> test
and another <div>foo <em>bar</em> foo</div> grr.</p>
and another <div>foo <em>bar</em> foo</div> grr.
Link to <a href="article.html">another article</a>.
Link to <a href="/absoute-article.html">absolute article</a>.
Link to <a href="../resource/back.jpg">back resource</a>.
Link to <a href="resource/forward.jpg">forward resource</a>.</p>
<pre class="prettyprint notranslate" translate="no"><code class="lang-html">&lt;div&gt;test *abc*&lt;div&gt;
</code></pre>
<img src="resources/foo.jpg">
Expand Down
4 changes: 4 additions & 0 deletions test/lessons/ja/test-one.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ TOC: First Article

This is a <span>foo *bar* foo</span> test
and another <div>foo *bar* foo</div> grr.
Link to [another article](article.html).
Link to [absolute article](/absoute-article.html).
Link to [back resource](../resource/back.jpg).
Link to [forward resource](resource/forward.jpg).

```html
<div>test *abc*<div>
Expand Down
4 changes: 4 additions & 0 deletions test/lessons/test-one.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ TOC: First Article

This is a <span>foo *bar* foo</span> test
and another <div>foo *bar* foo</div> grr.
Link to [another article](article.html).
Link to [absolute article](/absoute-article.html).
Link to [back resource](../resource/back.jpg).
Link to [forward resource](resource/forward.jpg).

```html
<div>test *abc*<div>
Expand Down

0 comments on commit a159a5c

Please sign in to comment.