<% const hasTree = subRoot.note.hasVisibleChildren(); // Collect HTML snippets by location const htmlSnippetsByLocation = {}; for (const htmlRelation of note.getRelations("shareHtml")) { const htmlNote = htmlRelation.targetNote; if (htmlNote) { let location = htmlNote.getLabelValue("shareHtmlLocation") || "content:end"; if (!location.includes(":")) { location = location + ":end"; } if (!htmlSnippetsByLocation[location]) { htmlSnippetsByLocation[location] = []; } htmlSnippetsByLocation[location].push(htmlNote.getContent()); } } const renderSnippets = (location) => { const snippets = htmlSnippetsByLocation[location]; return snippets ? snippets.join("\n") : ""; }; // ---- SEO: per-page URL / canonical / OG image / JSON-LD ---- const rootUrl = subRoot.note.getLabelValue("shareOpenGraphURL") || ""; const perNoteUrl = note.getLabelValue("shareOpenGraphURL"); const pageUrl = perNoteUrl || (rootUrl && note.noteId !== subRoot.note.noteId ? rootUrl + (note.shareId || note.noteId) : rootUrl); let ogImageRel = subRoot.note.getLabelValue("shareOpenGraphImage"); if (subRoot.note.hasRelation("shareOpenGraphImage")) { ogImageRel = `api/images/${subRoot.note.getRelation("shareOpenGraphImage").value}/image.png`; } const ogImage = ogImageRel ? rootUrl + ogImageRel : ""; const jsonLd = []; if (note.noteId === subRoot.note.noteId) { jsonLd.push({ "@context": "https://schema.org", "@type": "WebSite", name: subRoot.note.title, url: pageUrl, description: note.getLabelValue("shareDescription") || "" }); } else if (note.getLabelValue("publish") === "true") { jsonLd.push({ "@context": "https://schema.org", "@type": "BlogPosting", headline: note.title, url: pageUrl, datePublished: (note.getLabelValue("date") || note.dateCreated).slice(0, 10), dateModified: (note.utcDateModified || "").slice(0, 10), description: note.getLabelValue("shareDescription") || "", mainEntityOfPage: pageUrl, author: { "@type": "Person", name: subRoot.note.title } }); } else { jsonLd.push({ "@context": "https://schema.org", "@type": "CollectionPage", name: note.title, url: pageUrl, description: note.getLabelValue("shareDescription") || "" }); } %> <%- renderSnippets("head:start") %> <% for (const url of cssToLoad) { %> <% } %> <% for (const url of jsToLoad) { %> <% } %> <% if (note.hasLabel("shareDisallowRobotIndexing")) { %> <% } else { %> <% } %> <% const pageTitle = `${note.title}${note.noteId !== subRoot.note.noteId ? ` - ${subRoot.note.title}` : ""}`; const openGraphColor = subRoot.note.getLabelValue("shareOpenGraphColor"); const openGraphDomain = subRoot.note.getLabelValue("shareOpenGraphDomain"); %> <%= pageTitle %> <% if (pageUrl) { %><% } %> "> "> "> "> <%- renderSnippets("head:end") %> <% const logoWidth = subRoot.note.getLabelValue("shareLogoWidth") ?? 53; const logoHeight = subRoot.note.getLabelValue("shareLogoHeight") ?? 40; const mobileLogoHeight = logoHeight && logoWidth ? 32 / (logoWidth / logoHeight) : ""; const shareRootLink = subRoot.note.hasLabel("shareRootLink") ? sanitizeUrl(subRoot.note.getLabelValue("shareRootLink") ?? "") : `./${subRoot.note.noteId}`; const headingRe = /()(.+?)(<\/h[1-6]>)/g; const headingMatches = [...content.matchAll(headingRe)]; const headingSlugs = utils.slugifyHeadings(headingMatches.map((m) => m[2])); let headingIndex = 0; content = content.replaceAll(headingRe, (...match) => { const slug = headingSlugs[headingIndex++]; match[0] = match[0].replace(match[3], `#${match[3]}`); return match[0]; }); %> <%- renderSnippets("body:start") %>
ck-content<% } %><% if (isEmpty) { %> no-content<% } %>"> <%- renderSnippets("content:start") %>

<%= note.title %>

<% if (isEmpty && (!note.hasVisibleChildren() && note.type !== "book")) { %>

<%= t("share_page.no-content") %>

<% } else { %> <% content = content.replace(/${t( <%- content %> <% } %> <%- renderSnippets("content:end") %>
<% if (note.hasVisibleChildren() || note.type === "book") { %> <% } %>
<% if (!isEmpty && !isStatic) { %>
<% const lastUpdated = new Date(note.utcDateModified); %> <%- t("share_theme.last-updated", { date: ``}) %>
<% } %> <% if (hasTree) { %> <%- include("prev_next", { note: note, subRoot: subRoot }) %> <% } %> <% if (showLoginInShareTheme && !isStatic) { %> <% } %>
<% if (headingMatches.length > 1) { const level = (m) => parseInt(m[1].replace(/[]+/g, "")); const makeEntry = (i) => ({level: level(headingMatches[i]), name: headingMatches[i][2], slug: headingSlugs[i], children: []}); const toc = [ makeEntry(0) ]; const last = (arr = toc) => arr[arr.length - 1]; const getLevelArr = (lvl, arr = toc) => { if (arr[0].level === lvl) return arr; const top = last(arr); return top.children.length ? getLevelArr(lvl, top.children) : top.children; }; for (let m = 1; m < headingMatches.length; m++) { const target = getLevelArr(level(headingMatches[m])); target.push(makeEntry(m)); } %>

<%= t("share_theme.on-this-page") %>

    <% for (const entry of toc) { %> <%- include("toc_item", {entry}) %> <% } %>
<% } %>
<%- renderSnippets("body:end") %>