Skip to content

Commit 69a9535

Browse files
committed
rerun scripts
1 parent e0d0ff0 commit 69a9535

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

.github/workflows/gh-pages.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ jobs:
6666
.then(html => {
6767
// Set the current document's HTML to the fetched content
6868
document.documentElement.innerHTML = html;
69+
// After setting `elm.innerHTML = ...`, run scripts manually
70+
elm.querySelectorAll('script').forEach(oldScript => {
71+
const newScript = document.createElement('script');
72+
// copy over all attributes (e.g. src, type, async, etc.)
73+
for (const { name, value } of oldScript.attributes) {
74+
newScript.setAttribute(name, value);
75+
}
76+
// copy inline code or fallback to src-based loading
77+
newScript.textContent = oldScript.textContent;
78+
// replace the old <script> so the browser will actually execute it
79+
oldScript.replaceWith(newScript);
80+
});
81+
6982
})
7083
.catch(error => {
7184
console.error('There was a problem with the fetch operation:', error);

0 commit comments

Comments
 (0)