mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 12:52:26 +00:00
Scope markdown view scripts to reload content
This commit is contained in:
1 parent
f087076401
commit
50f7fe9657
6 files changed
+303
-279
No files matched your search
+51
-47
@@ -16,60 +16,64 @@
|
||||
</section>
|
||||
|
||||
<script>
|
||||
// Provide no-op fallback loggers so embeds stay functional if bitvidLogger is unavailable.
|
||||
const noopLogger = {
|
||||
log: () => {},
|
||||
info: () => {},
|
||||
warn: () => {},
|
||||
error: () => {},
|
||||
};
|
||||
const dev = window.bitvidLogger?.dev || noopLogger;
|
||||
const user = window.bitvidLogger?.user || noopLogger;
|
||||
(() => {
|
||||
// Provide no-op fallback loggers so embeds stay functional if bitvidLogger is unavailable.
|
||||
const noopLogger = {
|
||||
log: () => {},
|
||||
info: () => {},
|
||||
warn: () => {},
|
||||
error: () => {},
|
||||
};
|
||||
const dev = window.bitvidLogger?.dev || noopLogger;
|
||||
const user = window.bitvidLogger?.user || noopLogger;
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
// Fetch the Markdown file
|
||||
const response = await fetch("content/getting-started.md");
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to load getting-started.md");
|
||||
}
|
||||
const loadMarkdown = async () => {
|
||||
try {
|
||||
// Fetch the Markdown file
|
||||
const response = await fetch("content/getting-started.md");
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to load getting-started.md");
|
||||
}
|
||||
|
||||
const markdownText = await response.text();
|
||||
const markdownText = await response.text();
|
||||
|
||||
// Convert to HTML with Marked (assuming marked is globally available)
|
||||
const html = marked.parse(markdownText);
|
||||
// Convert to HTML with Marked (assuming marked is globally available)
|
||||
const html = marked.parse(markdownText);
|
||||
|
||||
// Insert into #markdown-container
|
||||
const container = document.getElementById("markdown-container");
|
||||
if (container) {
|
||||
container.innerHTML = html;
|
||||
// Insert into #markdown-container
|
||||
const container = document.getElementById("markdown-container");
|
||||
if (container) {
|
||||
container.innerHTML = html;
|
||||
|
||||
const highlighter = window.hljs;
|
||||
const highlight =
|
||||
highlighter && typeof highlighter.highlightElement === "function"
|
||||
? (block) => highlighter.highlightElement(block)
|
||||
: highlighter && typeof highlighter.highlightBlock === "function"
|
||||
? (block) => highlighter.highlightBlock(block)
|
||||
: null;
|
||||
const highlighter = window.hljs;
|
||||
const highlight =
|
||||
highlighter && typeof highlighter.highlightElement === "function"
|
||||
? (block) => highlighter.highlightElement(block)
|
||||
: highlighter && typeof highlighter.highlightBlock === "function"
|
||||
? (block) => highlighter.highlightBlock(block)
|
||||
: null;
|
||||
|
||||
if (highlight) {
|
||||
container.querySelectorAll("pre code").forEach((block) => {
|
||||
try {
|
||||
highlight(block);
|
||||
} catch (highlightError) {
|
||||
dev.warn("Failed to highlight code block.", highlightError);
|
||||
}
|
||||
});
|
||||
if (highlight) {
|
||||
container.querySelectorAll("pre code").forEach((block) => {
|
||||
try {
|
||||
highlight(block);
|
||||
} catch (highlightError) {
|
||||
dev.warn("Failed to highlight code block.", highlightError);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
user.error("Error loading 'Getting Started' content:", err);
|
||||
const container = document.getElementById("markdown-container");
|
||||
if (container) {
|
||||
container.innerHTML = `
|
||||
<p class="text-critical-strong">Error loading content. Please try again later.</p>
|
||||
`;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
user.error("Error loading 'Getting Started' content:", err);
|
||||
const container = document.getElementById("markdown-container");
|
||||
if (container) {
|
||||
container.innerHTML = `
|
||||
<p class="text-critical-strong">Error loading content. Please try again later.</p>
|
||||
`;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
loadMarkdown();
|
||||
})();
|
||||
</script>
|
||||
Reference in new issue
Block a user