✨ Post embed image
This commit is contained in:
@@ -1,24 +1,32 @@
|
|||||||
import { createMarkdownExit } from "markdown-exit"
|
import {
|
||||||
|
createMarkdownExit,
|
||||||
|
type PluginWithParams
|
||||||
|
} from "markdown-exit"
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import texmath from "markdown-it-texmath"
|
import texmath from "markdown-it-texmath"
|
||||||
import katex from "katex"
|
import katex from "katex"
|
||||||
|
|
||||||
export function useMarkdownProcessor() {
|
export function useMarkdownProcessor() {
|
||||||
|
const serverUrl = useSolarNetworkUrl()
|
||||||
|
|
||||||
const processor = createMarkdownExit({
|
const processor = createMarkdownExit({
|
||||||
breaks: true,
|
breaks: true,
|
||||||
html: true,
|
html: true,
|
||||||
linkify: true,
|
linkify: true,
|
||||||
typographer: true
|
typographer: true
|
||||||
|
})
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
}).use(texmath, {
|
.use(texmath, {
|
||||||
engine: katex,
|
engine: katex,
|
||||||
delimiters: "dollars",
|
delimiters: "dollars",
|
||||||
katexOptions: { macros: { "\\RR": "\\mathbb{R}" } }
|
katexOptions: { macros: { "\\RR": "\\mathbb{R}" } }
|
||||||
})
|
})
|
||||||
|
.use(imgSolarNetworkPlugin, { serverUrl: serverUrl })
|
||||||
|
|
||||||
|
// Keep the empty lines
|
||||||
const defaultParagraphRenderer =
|
const defaultParagraphRenderer =
|
||||||
processor.renderer.rules.paragraph_open ||
|
processor.renderer.rules.paragraph_open ||
|
||||||
((tokens, idx, options, env, self) =>
|
((tokens, idx, options, _env, self) =>
|
||||||
self.renderToken(tokens, idx, options))
|
self.renderToken(tokens, idx, options))
|
||||||
processor.renderer.rules.paragraph_open = function (
|
processor.renderer.rules.paragraph_open = function (
|
||||||
tokens,
|
tokens,
|
||||||
@@ -53,3 +61,32 @@ export function useMarkdownProcessor() {
|
|||||||
render: (content: string) => processor.render(content)
|
render: (content: string) => processor.render(content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const imgSolarNetworkPlugin: PluginWithParams = (
|
||||||
|
md,
|
||||||
|
{ serverUrl }: { serverUrl: string }
|
||||||
|
) => {
|
||||||
|
const originalImageRender = md.renderer.rules.image!
|
||||||
|
|
||||||
|
md.renderer.rules.image = (
|
||||||
|
tokens,
|
||||||
|
index,
|
||||||
|
options,
|
||||||
|
env,
|
||||||
|
self
|
||||||
|
): Promise<string> | string => {
|
||||||
|
tokens[index]!.attrSet("loading", "lazy")
|
||||||
|
|
||||||
|
const ogSrc = tokens[index]!.attrGet("src")
|
||||||
|
if (ogSrc && ogSrc.startsWith("solian://files/")) {
|
||||||
|
const newSrc = ogSrc.replace(
|
||||||
|
"solian://files/",
|
||||||
|
serverUrl + "/drive/files/"
|
||||||
|
)
|
||||||
|
tokens[index]!.attrSet("src", newSrc)
|
||||||
|
tokens[index]!.attrSet("class", "prose-img-solar-network")
|
||||||
|
}
|
||||||
|
|
||||||
|
return originalImageRender(tokens, index, options, env, self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -68,10 +68,15 @@
|
|||||||
</article>
|
</article>
|
||||||
|
|
||||||
<!-- Attachments within Content Section -->
|
<!-- Attachments within Content Section -->
|
||||||
<attachment-list :attachments="post.attachments || []" />
|
<attachment-list v-if="post.type != 1" :attachments="post.attachments || []" />
|
||||||
</v-card>
|
</v-card>
|
||||||
|
|
||||||
<v-card title="Replies" prepend-icon="mdi-comment-text-multiple" color="transparent" flat>
|
<v-card
|
||||||
|
title="Replies"
|
||||||
|
prepend-icon="mdi-comment-text-multiple"
|
||||||
|
color="transparent"
|
||||||
|
flat
|
||||||
|
>
|
||||||
<replies-list :params="{ postId: post.id }" />
|
<replies-list :params="{ postId: post.id }" />
|
||||||
</v-card>
|
</v-card>
|
||||||
</div>
|
</div>
|
||||||
@@ -90,7 +95,7 @@
|
|||||||
<v-chip
|
<v-chip
|
||||||
v-for="category in post.categories"
|
v-for="category in post.categories"
|
||||||
:key="category.id"
|
:key="category.id"
|
||||||
prepend-icon="mdi-tshape"
|
prepend-icon="mdi-shape"
|
||||||
rounded
|
rounded
|
||||||
>
|
>
|
||||||
{{ category.slug }}
|
{{ category.slug }}
|
||||||
@@ -248,4 +253,30 @@ function handleReaction(symbol: string, attitude: number, delta: number) {
|
|||||||
post.value.reactionsCount = reactions
|
post.value.reactionsCount = reactions
|
||||||
post.value.reactionsMade = reactionsMade
|
post.value.reactionsMade = reactionsMade
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
setTimeout(() => makeEmbedImageClickable(), 100)
|
||||||
|
})
|
||||||
|
|
||||||
|
function makeEmbedImageClickable() {
|
||||||
|
const elements = document.getElementsByClassName("prose-img-solar-network")
|
||||||
|
let count = 0;
|
||||||
|
for (const element of elements) {
|
||||||
|
if (element instanceof HTMLImageElement) {
|
||||||
|
count += 1;
|
||||||
|
element.addEventListener("click", (evt) => {
|
||||||
|
const targetImg = evt.target as HTMLImageElement
|
||||||
|
window.open("/files/" + targetImg.src.split("/").findLast((_) => true))
|
||||||
|
})
|
||||||
|
element.style['cursor'] = 'pointer';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(`[Article] Made ${count} image(s) clickable in the article.`);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.prose-img-solar-network img {
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user