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

Infrastructure: Remove unexpected shared/js/app.js change not yet in w3c/aria-practices and file read check for experimental content #330

Merged
merged 1 commit into from
Jun 25, 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
2 changes: 0 additions & 2 deletions ARIA/apg/index/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ if (enableSidebar) document.body.classList.add('has-sidebar');
<ul>
<li><a href="#examples_by_role_label">Examples by Role</a></li>
<li><a href="#examples_by_props_label">Examples by Properties and States</a></li>

</ul>
<section id="examples_by_roles">
<h2 id="examples_by_role_label">Examples by Role</h2>
Expand Down Expand Up @@ -950,7 +949,6 @@ if (enableSidebar) document.body.classList.add('has-sidebar');
</tr></tbody>
</table>
</section>

</div>


Expand Down
14 changes: 4 additions & 10 deletions content-assets/wai-aria-practices/shared/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@
// Determine we are on an example page
if (!document.location.href.match(/examples\/[^/]+\.html/)) return;

const isExperimental =
document.querySelector('main')?.getAttribute('data-content-phase') ===
'experimental';

const usageWarningLink = isExperimental
? '/templates/experimental-example-usage-warning.html'
: '/templates/example-usage-warning.html';

// Generate the usage warning link using app.js link as a starting point
const scriptSource = document
.querySelector('[src$="app.js"]')
.getAttribute('src');

const fetchSource = scriptSource.replace('/js/app.js', usageWarningLink);
const fetchSource = scriptSource.replace(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is automatic -- coming from running node ./scripts/pre-build

'/js/app.js',
'/templates/example-usage-warning.html'
);

// Load and parse the usage warning and insert it before the h1
const html = await (await fetch(fetchSource)).text();
Expand Down
23 changes: 19 additions & 4 deletions scripts/pre-build/library/transformExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,30 @@ const getExampleLastModifiedDate = require("./getExampleLastModifiedDate");
const loadNoticeCommon = async ({ isExperimental }) => {
let relativePath;
if (isExperimental) {
// Depends on https://github.com/w3c/aria-practices/pull/2977 being merged
relativePath =
"content/shared/templates/experimental-example-usage-warning.html";
} else {
relativePath = "content/shared/templates/example-usage-warning.html";
}
const templateSourcePath = path.resolve(sourceRoot, relativePath);
const noticeContent = await fs.readFile(templateSourcePath, {
encoding: "utf8",
});

let templateSourcePath = path.resolve(sourceRoot, relativePath);

let noticeContent;
try {
noticeContent = await fs.readFile(templateSourcePath, {
encoding: "utf8",
});
} catch (e) {
console.warn(`${e.message}\nReverting to using default example-usage-warning.html ...\n`);

// Could happen if experimental-example-usage-warning.html doesn't exist
relativePath = "content/shared/templates/example-usage-warning.html";
templateSourcePath = path.resolve(sourceRoot, relativePath);
noticeContent = await fs.readFile(templateSourcePath, {
encoding: "utf8",
});
}

return async (sourcePath) => {
const html = parseHtml(noticeContent);
Expand Down