Skip to content

Commit ecb25c0

Browse files
committed
refactor: robust pathPrefix handling; all internal links now consistent
1 parent 9f81e7a commit ecb25c0

File tree

55 files changed

+310
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+310
-169
lines changed

package-lock.json

Lines changed: 242 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@11ty/eleventy-navigation": "^0.3.3",
4646
"@cspell/dict-fr-fr": "^2.1.2",
4747
"axios": "^1.7.5",
48-
"broken-link-checker": "^0.6.7",
48+
"broken-link-checker": "^0.7.8",
4949
"cross-env": "^7.0.3",
5050
"cspell": "^6.18.1",
5151
"dotenv": "^16.4.5",

scripts/link-checker.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ const siteChecker = new blc.SiteChecker(
128128
};
129129
brokenLinks.push(existingPage);
130130
}
131-
131+
// Ensure links array exists (defensive)
132+
if (!Array.isArray(existingPage.links)) {
133+
existingPage.links = [];
134+
}
132135
existingPage.links.push({
133136
link: result.url.original,
134137
linkText: result.html.text || "N/A"

src/_data/pathPrefix.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ module.exports = () => {
44
const pathPrefix = process.env.PATH_PREFIX;
55

66
if (pathPrefix) {
7-
// Ensure prefix starts with '/' but NO trailing slash
8-
const normalizedPrefix = `/${pathPrefix.replace(/^\/+|\/+$/g, '')}`;
9-
return normalizedPrefix;
7+
// Only add leading slash if pathPrefix is set, and remove any leading/trailing slashes from the value
8+
return '/' + pathPrefix.replace(/^\/+|\/+$/g, '');
109
}
1110

1211
// Default to empty string for main repo (no prefix needed)

src/_includes/partials/breadcrumbs.njk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Canada.ca > Digital Accessibility Toolkit > How to’s > Create web content > Ac
6464
{% set url = page.url | replace("/", "") %}
6565
{% if url != locale %}
6666
<li property="itemListElement" typeof="ListItem">
67-
<a property="item" typeof="WebPage" href="{{ pathPrefix }}/{{ locale }}/">{{ settings[locale].metaTitle }}</a>
67+
<a property="item" typeof="WebPage" href="{% if pathPrefix %}{{ pathPrefix }}{% endif %}/{{ locale }}/">{{ settings[locale].metaTitle }}</a>
6868
<meta property="position" content="2">
6969
</li>
7070
{% endif %}
@@ -77,7 +77,7 @@ Canada.ca > Digital Accessibility Toolkit > How to’s > Create web content > Ac
7777
{% if subject %}
7878
{% for breadcrumb in subject %}
7979
<li property="itemListElement" typeof="ListItem">
80-
<a property="item" typeof="WebPage" href="{{ pathPrefix }}/{{ locale }}/{{ tagList.tags[locale][breadcrumb] | stripTagsSlugify or tagList.subjects[locale][breadcrumb] | stripTagsSlugify }}">
80+
<a property="item" typeof="WebPage" href="{% if pathPrefix %}{{ pathPrefix }}{% endif %}/{{ locale }}/{{ tagList.tags[locale][breadcrumb] | stripTagsSlugify or tagList.subjects[locale][breadcrumb] | stripTagsSlugify }}">
8181
<span property="name">{{ tagList.tags[locale][breadcrumb] or tagList.subjects[locale][breadcrumb] }}</span>
8282
</a>
8383
<meta property="position" content="{{ counter }}">
@@ -91,7 +91,7 @@ Canada.ca > Digital Accessibility Toolkit > How to’s > Create web content > Ac
9191
{% for breadcrumb in tags %}
9292
{% if breadcrumb != "updatesMain" %}
9393
<li property="itemListElement" typeof="ListItem">
94-
<a property="item" typeof="WebPage" href="{{ pathPrefix }}/{{ locale }}/{{ tagList.tags[locale][breadcrumb] | stripTagsSlugify or tagList.subjects[locale][breadcrumb] | stripTagsSlugify }}">
94+
<a property="item" typeof="WebPage" href="{% if pathPrefix %}{{ pathPrefix }}{% endif %}/{{ locale }}/{{ tagList.tags[locale][breadcrumb] | stripTagsSlugify or tagList.subjects[locale][breadcrumb] | stripTagsSlugify }}">
9595
<span property="name">{{ tagList.tags[locale][breadcrumb] or tagList.subjects[locale][breadcrumb] }}</span>
9696
</a>
9797
<meta property="position" content="{{ counter }}">

src/_includes/partials/collectionsMain.njk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<div class="container">
32
<div class="row wb-eqht mrgn-tp-lg gc-srvinfo">
43
{% for item in collections.main | sort(false, false, 'data.title') | localeMatch(locale) %}

src/_includes/partials/office-toc.njk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
<div class="gc-stp-stp">
3232
<div class="toc row mrgn-tp-lg">
3333
<ul class="wb-eqht-grd">
34-
<li class="col-md-4 col-sm-6"><a class="list-group-item{% if page.url === indexURL %} active{% endif %}"{% if page.url===indexURL %} aria-current="page"{% endif %}{% if page.url !=indexURL %} href="{{ pathPrefix }}{{ indexURL | replace('/', '') }}"{% endif %}>{{ indexTitle }} <small class="visible-xs-inline visible-sm-block visible-md-block visible-lg-block"> {{ inOffice }} {{ version }}</small></a></li>
34+
<li class="col-md-4 col-sm-6"><a class="list-group-item{% if page.url === indexURL %} active{% endif %}"{% if page.url===indexURL %} aria-current="page"{% endif %}{% if page.url !=indexURL %} href="{{ pathPrefix }}{{ indexURL }}"{% endif %}>{{ indexTitle }} <small class="visible-xs-inline visible-sm-block visible-md-block visible-lg-block"> {{ inOffice }} {{ version }}</small></a></li>
3535
{% for item in collections | localeMatch(locale) %}
3636
{% set title = item.data.title %}
37-
<li class="col-md-4 col-sm-6" {% if page.url==item.url %} aria-current="page" {% endif %}><a class="list-group-item{% if page.url == item.url %} active{% endif %}"{% if page.url !=item.url %} href="{{ pathPrefix }}/{{ item.url | replace('/', '') }}"{% endif %}>
37+
<li class="col-md-4 col-sm-6" {% if page.url==item.url %} aria-current="page" {% endif %}><a class="list-group-item{% if page.url == item.url %} active{% endif %}"{% if page.url !=item.url %} href="{{ pathPrefix }}{{ item.url }}"{% endif %}>
3838
{% if item.data.fontIcon %}
3939
<i class="fas fa-lg {{ item.data.fontIcon }}" aria-hidden="true"></i>
4040
{% endif %}
@@ -47,7 +47,7 @@
4747
<div class="well">
4848
{% set versionSlug = version | slugify %}
4949
{% set otherVersionSlug = otherVersion | slugify %}
50-
<p class="mrgn-tp-md">{{ tryText }} <a href="{{ pathPrefix }}/{{ page.url | replace(versionSlug,otherVersionSlug) | replace('/', '') }}">{{ title | replace(inOffice + " " + version,"") }}<small><strong> {{ inOffice }} {{ otherVersion }}</strong></small></a></p>
50+
<p class="mrgn-tp-md">{{ tryText }} <a href="{{ pathPrefix }}{{ page.url | replace(versionSlug,otherVersionSlug) }}">{{ title | replace(inOffice + " " + version,"") }}<small><strong> {{ inOffice }} {{ otherVersion }}</strong></small></a></p>
5151
</div>
5252

5353
{% endif %}

src/_includes/partials/pageList.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
{% else %}
119119
{% if entry.data.tags %}
120120
<section class="col-md-6" data-wb-tags="{{ entry.data.subject }} {{ entry.data.tags }}{% for items in isLanding[6] %}{% if items != "m" %} notLanding{% endif %}{% endfor %}">
121-
<h2 class="h4"><a href="{{ pathPrefix }}{{ entry.url }}">{{ entry.data.title | striptags(true) | escape | nl2br }}</a></h2>
121+
<h2 class="h4"><a href="{{ entry.url }}">{{ entry.data.title | striptags(true) | escape | nl2br }}</a></h2>
122122
{% if settings.env == "local" %}
123123
{% if entry.data.subject %}
124124
<p><strong>subject{% if locale === "fr" %} {% endif %}:</strong> <span class="label label-success">{{ entry.data.subject }}</span></p>

src/_includes/partials/pageListTable.njk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@
105105
{% else %}
106106
<tr{% for items in isLanding[6] %}{% if items === "m" %} class="success" data-wb-tags="isLanding"{% else %} data-wb-tags="isPage"{% endif %}{% endfor %}>
107107
<td data-wb-tags="col_1">
108-
<a href="{{ pathPrefix }}/{{ entry.url | replace('/', '') }}">{{ entry.data.title | safe }}</a></td>
108+
<a href="{{ entry.url }}">{{ entry.data.title | safe }}</a></td>
109109
<td data-wb-tags="col_2">
110110
{% if entry.data.toggle %}
111-
<a href="{{ pathPrefix }}/{{ otherLocale }}/{{ entry.data.toggle }}" hreflang="{{ otherLang }}">{% if locale === "en" %}French version{% else %}Version anglaise{% endif %} <span class="wb-inv">{% if locale === "en" %}of{% else %}de{% endif %} {{ entry.data.title | safe }}</span></a>
111+
<a href="{{ pathPrefix }}{{ otherLocale }}/{{ entry.data.toggle }}" hreflang="{{ otherLang }}">{% if locale === "en" %}French version{% else %}Version anglaise{% endif %} <span class="wb-inv">{% if locale === "en" %}of{% else %}de{% endif %} {{ entry.data.title | safe }}</span></a>
112112
{% else %}
113113
<strong>{{ missingToggle }}</strong>
114114
{% endif %}

src/_includes/partials/updatesMain.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</p>
1818
<ul class="row wb-eqht-grd list-unstyled small">
1919
{% for item in collections.updatesMain | sort(attribute='date', reverse=true) | localeMatch(locale) %}
20-
<li class="col-xs-12 col-sm-6 mrgn-tp-sm mrgn-bttm-sm"><a href="{{ pathPrefix }}{{ item.url }}">{{ item.data.title }} <small class="visible-xs-inline visible-sm-block visible-md-block visible-lg-block"><time>{{ item.date | postDate }}</time></small></a></li>
20+
<li class="col-xs-12 col-sm-6 mrgn-tp-sm mrgn-bttm-sm"><a href="{{ pathPrefix }}{{ item.url }} ">{{ item.data.title }} <small class="visible-xs-inline visible-sm-block visible-md-block visible-lg-block"><time>{{ item.date | postDate }}</time></small></a></li>
2121
{% endfor %}
2222
</ul>
2323
</section>

0 commit comments

Comments
 (0)