mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-24 21:34:06 -06:00
Added callouts
This commit is contained in:
parent
e142f37e8d
commit
69f10bcd19
@ -7,6 +7,7 @@ function htmlToElement(html) {
|
||||
|
||||
function initPopover(baseURL, useContextualBacklinks, renderLatex) {
|
||||
const basePath = baseURL.replace(window.location.origin, "")
|
||||
const regex = /\[!.+\]-? /;
|
||||
fetchData.then(({ content }) => {
|
||||
const links = [...document.getElementsByClassName("internal-link")]
|
||||
links
|
||||
@ -17,7 +18,7 @@ function initPopover(baseURL, useContextualBacklinks, renderLatex) {
|
||||
const linkDest = content[li.dataset.src]
|
||||
const popoverElement = `<div class="popover">
|
||||
<h3>${linkDest.title}</h3>
|
||||
<p>${highlight(removeMarkdown(linkDest.content), li.dataset.ctx)}...</p>
|
||||
<p>${highlight(removeMarkdown(linkDest.content), li.dataset.ctx).replace(regex, "")}...</p>
|
||||
<p class="meta">${new Date(linkDest.lastmodified).toLocaleDateString()}</p>
|
||||
</div>`
|
||||
el = htmlToElement(popoverElement)
|
||||
@ -26,7 +27,7 @@ function initPopover(baseURL, useContextualBacklinks, renderLatex) {
|
||||
if (linkDest) {
|
||||
const popoverElement = `<div class="popover">
|
||||
<h3>${linkDest.title}</h3>
|
||||
<p>${removeMarkdown(linkDest.content).split(" ", 20).join(" ")}...</p>
|
||||
<p>${removeMarkdown(linkDest.content).split(" ", 20).join(" ").replace(regex, "")}...</p>
|
||||
<p class="meta">${new Date(linkDest.lastmodified).toLocaleDateString()}</p>
|
||||
</div>`
|
||||
el = htmlToElement(popoverElement)
|
||||
|
||||
@ -138,12 +138,13 @@ const highlight = (content, term) => {
|
||||
}
|
||||
|
||||
const resultToHTML = ({ url, title, content, term }) => {
|
||||
const regex = /\[!.+\]-? /;
|
||||
const text = removeMarkdown(content)
|
||||
const resultTitle = highlight(title, term)
|
||||
const resultText = highlight(text, term)
|
||||
return `<button class="result-card" id="${url}">
|
||||
<h3>${resultTitle}</h3>
|
||||
<p>${resultText}</p>
|
||||
<p>${resultText.replace(regex, "")}</p>
|
||||
</button>`
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta
|
||||
name="description"
|
||||
content="{{if .IsHome}}{{$.Site.Data.config.description}}{{else}}{{.Summary}}{{end}}"
|
||||
content="{{if .IsHome}}{{$.Site.Data.config.description}}{{else}}{{ replaceRE ` \[!.+\]-? ` `` .Summary }}{{end}}"
|
||||
/>
|
||||
<title>
|
||||
{{ if .Title }}{{ .Title }}{{ else }}{{ $.Site.Data.config.page_title }}{{
|
||||
|
||||
@ -55,4 +55,29 @@
|
||||
{{/* Add jumpable anchors */}}
|
||||
{{ $content = $content | replaceRE "(<h[1-9] id=\"([^\"]+)\">)(.+)(</h[1-9]>)" `<a href="#${2}">${1}<span class="hanchor" ariaLabel="Anchor"># </span>${3}${4}</a>` }}
|
||||
|
||||
{{/* Callouts */}}
|
||||
{{ $content = $content | replaceRE "<blockquote>" "<blockquote class=callout>" }}
|
||||
{{ $blockquoteclasses := findRE `\[!.+\]` $content }}
|
||||
{{ $blockquoteclasses1 := findRE "<blockquote.*?>(.|\n)*?</blockquote>" $content }}
|
||||
{{ $blockquotetags := findRE `blockquote class=callout` $content }}
|
||||
{{ $counter := 0 }}
|
||||
{{ $counter1 := 0 }}
|
||||
{{ $finder := index $blockquoteclasses1 $counter }}
|
||||
{{range $blockquotetags}}
|
||||
{{ $finder = index $blockquoteclasses1 $counter }}
|
||||
{{ if (in $finder "[!") }}
|
||||
{{ $inner := index $blockquoteclasses $counter1 }}
|
||||
{{ $inner = $inner | replaceRE `\[!(.+)\]` `${1}` }}
|
||||
{{ $inner = printf "blockquote class=%s-callout" $inner}}
|
||||
{{ $content = replace $content . $inner 1}}
|
||||
{{ $counter1 = add $counter1 1 }}
|
||||
{{ else }}
|
||||
{{ $inner := print "blockquote" }}
|
||||
{{ $content = replace $content . $inner 1}}
|
||||
{{ end }}
|
||||
{{ $counter = add $counter 1 }}
|
||||
{{end}}
|
||||
{{ $content = $content | replaceRE `\[!.+\]-?` "" }}
|
||||
{{ $content = $content | replaceRE "blockquote class=callout" "blockquote" }}
|
||||
|
||||
{{ $content | safeHTML }}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user