Skip to content

Commit

Permalink
Update formatForJekyll.js to only include skipto.js once with any app…
Browse files Browse the repository at this point in the history
…licable data attribs; update transformHomepage.js to remove conflicting style tag
  • Loading branch information
howard-e committed Jan 23, 2024
1 parent 6c6ac9b commit 64d1b52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 11 additions & 6 deletions scripts/pre-build/library/formatForJekyll.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ const formatForJekyll = ({
const permalink = `/ARIA/apg/${sitePath}`;

let headContent = '';
let skipToData = null;
let skipToScriptTag = `<script src="{{ '/content-assets/wai-aria-practices/shared/js/skipto.js' | relative_url }}"`;
let skipToScriptData = null;

if (head) {
skipToScriptData = head.querySelector('script[data-skipto]')?.getAttribute('data-skipto');
if (skipToScriptData) skipToScriptTag += `data-skipto="${skipToScriptData}"`;

// Remove skipto.js script tag in head to avoid loading twice; it's always included through `formattedSkipToScript`
const skipToScriptTagToRemove = head.querySelectorAll('script').find(el => el.getAttribute('src').includes('js/skipto.js'));
if (skipToScriptTagToRemove) skipToScriptTagToRemove.remove();
headContent = head.innerHTML;
skipToData = head.querySelector('script[data-skipto]')?.getAttribute('data-skipto');
}
skipToScriptTag += '></script>';

// Must be formatted because html which is indented by 4 spaces
// will be interpreted as a code block by the markdown engine
const formattedHead = prettier.format(headContent, { parser: "html" });
const formattedSkipToScript = prettier.format(skipToScriptTag, { parser: "html" });

return `---
# This file was generated by scripts/pre-build/library/formatForJekyll.js
Expand Down Expand Up @@ -84,10 +92,7 @@ ${
<div>
${content}
</div>
<script
src="{{ '/content-assets/wai-aria-practices/shared/js/skipto.js' | relative_url }}"
${skipToData ? `data-skipto="${skipToData}"` : 'data-skipto'}
></script>
${formattedSkipToScript}
${/* `, { parser: "html" })} */ ""}`;
};

Expand Down
4 changes: 3 additions & 1 deletion scripts/pre-build/library/transformHomepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ const transformHomepage = async (sourcePath, sourceContents) => {
<div class="bottom-off-white-section off-white-section"></div>
`;

// TODO: Remove conflicting img css properties
// Remove conflicting `img { *` CSS properties; safe to do while the source apg-home.html ONLY has that single rule
// defined inside it's `<style>` tag
html.querySelector("head").querySelector("style").remove();

return formatForJekyll({
title: "ARIA Authoring Practices Guide",
Expand Down

0 comments on commit 64d1b52

Please sign in to comment.