Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for data-skipto parameters #292

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions scripts/pre-build/library/formatForJekyll.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,30 @@ const formatForJekyll = ({
content,
enableSidebar = false,
githubPath,
head = "",
head = null,
footer = null,
}) => {
const permalink = `/ARIA/apg/${sitePath}`;

let headContent = '';
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;
}
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(head, { parser: "html" });
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 @@ -76,9 +92,7 @@ ${
<div>
${content}
</div>
<script
src="{{ '/content-assets/wai-aria-practices/shared/js/skipto.js' | relative_url }}"
></script>
${formattedSkipToScript}
${/* `, { parser: "html" })} */ ""}`;
};

Expand Down
2 changes: 1 addition & 1 deletion scripts/pre-build/library/transformAboutContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const transformAboutContent = async (sourcePath, sourceContents) => {
removeDuplicateMainTag(html.querySelector("body").innerHTML)
),
enableSidebar,
head: html.querySelector("head").innerHTML,
head: html.querySelector("head"),
});
};

Expand Down
2 changes: 1 addition & 1 deletion scripts/pre-build/library/transformExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const transformExample = async (sourcePath, sourceContents) => {
wrapTablesWithResponsiveDiv(html.querySelector("body").innerHTML)
),
enableSidebar: true,
head: html.querySelector("head").innerHTML,
head: html.querySelector("head"),
footer: `
<div class="example-page-footer">
<p>${relatedIssuesLink}</p>
Expand Down
2 changes: 1 addition & 1 deletion scripts/pre-build/library/transformExampleIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const transformExampleIndex = async (sourcePath, sourceContents) => {
githubPath,
content: removeDuplicateMainTag(html.querySelector("body").innerHTML),
enableSidebar: true,
head: html.querySelector("head").innerHTML,
head: html.querySelector("head"),
});
};

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

// 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",
sitePath,
githubPath,
content: homepageContent,
head: html.querySelector("head"),
});
};

Expand Down
2 changes: 1 addition & 1 deletion scripts/pre-build/library/transformPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const transformPattern = async (sourcePath, sourceContents) => {
githubPath,
content: removeDuplicateMainTag(html.querySelector("body").innerHTML),
enableSidebar: true,
head: html.querySelector("head").innerHTML,
head: html.querySelector("head"),
footer: "",
});
};
Expand Down
2 changes: 1 addition & 1 deletion scripts/pre-build/library/transformPatternIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const transformPatternIndex = async (sourcePath, sourceContents) => {
githubPath,
content,
enableSidebar: false,
head: html.querySelector("head").innerHTML,
head: html.querySelector("head"),
});
};

Expand Down
2 changes: 1 addition & 1 deletion scripts/pre-build/library/transformPractice.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const transformPractice = async (sourcePath, sourceContents) => {
removeDuplicateMainTag(html.querySelector("body").innerHTML)
),
enableSidebar: true,
head: html.querySelector("head").innerHTML,
head: html.querySelector("head"),
});
};

Expand Down
2 changes: 1 addition & 1 deletion scripts/pre-build/library/transformPracticeIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const transformPatternIndex = async (sourcePath, sourceContents) => {
githubPath,
content,
enableSidebar: false,
head: html.querySelector("head").innerHTML,
head: html.querySelector("head"),
});
};

Expand Down