diff --git a/blog.html b/blog.html new file mode 100644 index 0000000..15138a1 --- /dev/null +++ b/blog.html @@ -0,0 +1,115 @@ + + + + + + + + + 博客 - RuyiAI + + + + + + + + + + +
+ + + + + +
+
+ + +
+

博客

+

+
+
+
+ +
+
+ + + + + + + + + diff --git a/blog.js b/blog.js new file mode 100644 index 0000000..7a0b76f --- /dev/null +++ b/blog.js @@ -0,0 +1,1114 @@ +(function () { + var docItems = { + "triton-on-riscv": { + title: "Triton 的 RISC-V 适配", + titleEn: "Triton on RISC-V", + desc: "发布时间:2026-2-26 | 作者:张洪滨", + descEn: "Published: 2026-2-26 | Author: Hongbin Zhang", + markdownUrl: "blog/triton-on-riscv.md" + } + }; + + var defaultDocId = "triton-on-riscv"; + var searchState = { + indexByLang: { zh: null, en: null }, + buildingByLang: { zh: null, en: null } + }; + + var inPageTocScrollCleanup = null; + + /** 解析文档 URL:相对路径以当前页面地址为基准,与 fetch 默认行为一致 */ + function resolveDocUrl(relativePath) { + try { + return new URL(relativePath, window.location.href).href; + } catch (e) { + return relativePath; + } + } + + function getEnglishDocUrlCandidates(mdUrl) { + if (!mdUrl || !/\.md$/i.test(mdUrl)) return []; + var a = mdUrl.replace(/\.md$/i, ".en.md"); + var b = mdUrl.replace(/\.md$/i, "-en.md"); + return a === b ? [a] : [a, b]; + } + + function getDocIdFromHash() { + var hash = window.location.hash.slice(1); + if (!hash && window.location.href.indexOf("#") !== -1) { + var parts = window.location.href.split("#"); + hash = (parts[1] || "").split("?")[0]; + } + return docItems[hash] ? hash : defaultDocId; + } + + function getCurrentLang() { + return (typeof window.ruyiaiLang !== "undefined" && window.ruyiaiLang === "en") ? "en" : "zh"; + } + + function escapeHtml(text) { + return String(text || "") + .replace(/&/g, "&") + .replace(//g, ">"); + } + + function parseInlineMarkdown(text) { + var html = escapeHtml(text); + html = html.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '$1'); + html = html.replace(/`([^`]+)`/g, "$1"); + html = html.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); + html = html.replace(/\*\*([^*]+)\*\*/g, "$1"); + html = html.replace(/\*([^*]+)\*/g, "$1"); + return html; + } + + function simpleMarkdownToHtml(md) { + var lines = String(md || "").replace(/\r\n?/g, "\n").split("\n"); + var out = []; + var inCode = false; + var inHtmlComment = false; + var codeBuf = []; + var paraBuf = []; + var listBuf = []; + var listType = null; + + function flushParagraph() { + if (!paraBuf.length) return; + out.push("

" + parseInlineMarkdown(paraBuf.join(" ")) + "

"); + paraBuf = []; + } + + function flushList() { + if (!listBuf.length) return; + var tag = listType === "ol" ? "ol" : "ul"; + out.push("<" + tag + ">"); + listBuf.forEach(function (item) { + out.push("
  • " + parseInlineMarkdown(item) + "
  • "); + }); + out.push(""); + listBuf = []; + listType = null; + } + + function flushCode() { + if (!inCode) return; + out.push("
    " + escapeHtml(codeBuf.join("\n")) + "
    "); + inCode = false; + codeBuf = []; + } + + function isTableSeparator(line) { + return /^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(line || ""); + } + + function parseTableCells(line) { + var text = String(line || "").trim(); + if (text.startsWith("|")) text = text.slice(1); + if (text.endsWith("|")) text = text.slice(0, -1); + return text.split("|").map(function (c) { return c.trim(); }); + } + + function isLikelyTableRow(line) { + return /^\s*\|.*\|\s*$/.test(line || ""); + } + + function isHtmlStartWithoutClose(line) { + return /^\s*<[A-Za-z][^>]*$/.test(line || ""); + } + + for (var i = 0; i < lines.length; i += 1) { + var line = lines[i]; + if (!inCode) { + if (inHtmlComment) { + if (line.indexOf("-->") !== -1) inHtmlComment = false; + continue; + } + if (line.indexOf("") === -1 || line.indexOf("")) { + inHtmlComment = true; + } + // Ignore HTML comments in fallback mode. + continue; + } + } + + if (/^\s*```/.test(line)) { + flushParagraph(); + flushList(); + if (inCode) { + flushCode(); + } else { + inCode = true; + codeBuf = []; + } + continue; + } + + if (inCode) { + codeBuf.push(line); + continue; + } + + var heading = line.match(/^(#{1,6})\s+(.*)$/); + if (heading) { + flushParagraph(); + flushList(); + var level = heading[1].length; + out.push("" + parseInlineMarkdown(heading[2]) + ""); + continue; + } + + // Horizontal rules like --- *** ___ + if (/^\s*([-*_]\s*){3,}\s*$/.test(line)) { + flushParagraph(); + flushList(); + out.push("
    "); + continue; + } + + // Blockquote lines like: > note + var blockquote = line.match(/^\s*>\s?(.*)$/); + if (blockquote) { + flushParagraph(); + flushList(); + out.push("

    " + parseInlineMarkdown(blockquote[1]) + "

    "); + continue; + } + + // Keep raw HTML blocks (e.g. ) as-is in fallback mode. + if (/^\s*<[^>]+>\s*$/.test(line)) { + flushParagraph(); + flushList(); + out.push(line.trim()); + continue; + } + + // Keep multi-line raw HTML tags (e.g.