Skip to content

Commit

Permalink
Remove unexpected shared/js/app.js change not yet in w3c/aria-practic…
Browse files Browse the repository at this point in the history
…es (#330)
  • Loading branch information
howard-e authored Jun 25, 2024
1 parent c2fec91 commit afadb2f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
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(
'/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

0 comments on commit afadb2f

Please sign in to comment.