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

Naive solution to embedding iframes into example pages #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions scripts/pre-build/library/loadExamples/loadExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const walkHtmlElements = require("../../utilities/walkHtmlElements");
const getTemplateBoilerplate = require("../getTemplateBoilerplate");
const { getHandleElement, getContent } = require("./handleElement");

const loadExample = async (filePath, { exampleRelativeDirectory }) => {
const loadExample = async (filePath, { exampleRelativeDirectory, reportId }) => {
const html = await fs.readFile(filePath, { encoding: "utf8" });
const slug = path.basename(filePath).slice(0, -5);
const permalink = `/index/${exampleRelativeDirectory}/${slug}`;
Expand All @@ -16,6 +16,13 @@ const loadExample = async (filePath, { exampleRelativeDirectory }) => {

const { title, head, body, outline, relatedLinks } = getContent();

const testReportSidebar = reportId ? `<li><a href="#test-report">Test Report</a></li>` : '';

const testReport = reportId ? `<section>
<h2 id="test-report" tabindex="-1">Test Report</h2>
<iframe width="560" height="315" src="https://aria-at.w3.org/reports/${reportId}"></iframe>
</section>` : '';

return {
fileName: `${slug}.md`,
fileContent: getTemplateBoilerplate({
Expand All @@ -36,10 +43,14 @@ const loadExample = async (filePath, { exampleRelativeDirectory }) => {
`;
})
.join(" ")}
${testReportSidebar}
</ul>
${relatedLinks}
</aside>
<div class="sidebar-right">${body}</div>
<div class="sidebar-right">
${body}
${testReport}
Copy link
Contributor

Choose a reason for hiding this comment

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

This conditionally appends the Test Report section to the body after the navigation link back to the design pattern. It seems to me that we'd want to preserve that always showing up at the end in the future

</div>
</div>
`,
}),
Expand Down
34 changes: 34 additions & 0 deletions scripts/pre-build/library/loadExamples/loadExamples.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const axios = require("axios");
const fs = require("fs/promises");
const path = require("path");
const { promiseFiles: getPaths } = require("node-dir");
Expand Down Expand Up @@ -56,12 +57,45 @@ const loadExamples = async () => {

await editAppJs({ destinationExamplesPath });

const query = `
query {
testPlanReports {
testPlanVersion {
id
testPlan {
id
}
gitSha
updatedAt
}
status
}
}
`

const response = await axios.post(
'https://aria-at.w3.org/api/graphql',
{ query }
)

const finalizedTestReports = response.data.data.testPlanReports.filter(testPlanVersion => testPlanVersion.status === 'FINALIZED')

for (const currentPath of exampleFilePaths) {
const exampleRelative = path.relative(examplesPath, currentPath);
const exampleRelativeDirectory = path.dirname(exampleRelative);

const exampleName = currentPath.replace('.html','').split('/').pop();
const reportUrls = finalizedTestReports.filter(report => report.testPlanVersion.testPlan.id === exampleName);
let url = reportUrls[0]
if (reportUrls.length > 1) {
// Get the latest SHA for an example
url = reportUrls.reduce((a, b) => Date.parse(a.testPlanVersion.updatedAt) > Date.parse(b.testPlanVersion.updatedAt) ? a : b
)
}

const { fileName, fileContent } = await loadExample(currentPath, {
exampleRelativeDirectory,
reportId: url && url.testPlanVersion.id
});

const destinationPath = path.join(
Expand Down
41 changes: 41 additions & 0 deletions scripts/pre-build/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scripts/pre-build/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"axios": "^0.24.0",
"fuzzysearch": "^1.0.3",
"lodash": "^4.17.21",
"node-dir": "^0.1.17",
Expand Down
12 changes: 12 additions & 0 deletions scripts/pre-build/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
# yarn lockfile v1


"axios@^0.24.0":
"integrity" "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA=="
"resolved" "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz"
"version" "0.24.0"
dependencies:
"follow-redirects" "^1.14.4"

"balanced-match@^1.0.0":
"integrity" "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
"resolved" "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz"
Expand Down Expand Up @@ -76,6 +83,11 @@
"resolved" "https://registry.npmjs.org/entities/-/entities-2.2.0.tgz"
"version" "2.2.0"

"follow-redirects@^1.14.4":
"integrity" "sha512-fhUl5EwSJbbl8AR+uYL2KQDxLkdSjZGR36xy46AO7cOMTrCMON6Sa28FmAnC2tRTDbd/Uuzz3aJBv7EBN7JH8A=="
"resolved" "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.6.tgz"
"version" "1.14.6"

"fs.realpath@^1.0.0":
"integrity" "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
"resolved" "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
Expand Down