Skip to content

Commit

Permalink
fix: formulate only parse once
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Apr 22, 2024
1 parent aaebeed commit ea32c03
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
6 changes: 6 additions & 0 deletions DEVELOPMENT.md
Expand Up @@ -12,6 +12,12 @@ serve

```bash
pnpm serve

# available links for serve test
# http://localhost:4000/share?id=20240408194841-jmgbco2&origin=http://192.168.3.3:6806&isSsr=false
#
# http://localhost:4000
# http://localhost:4000/s/20240408194841-jmgbco2
```

dev
Expand Down
36 changes: 8 additions & 28 deletions nuxt.config.ts
Expand Up @@ -9,7 +9,7 @@ const generateDynamicV = () => {
}

const isDev = process.env.NODE_ENV === "development"
const appBase = "/plugins/siyuan-blog/"
const appBase = "/"
const staticV = generateDynamicV()

// https://nuxt.com/docs/api/configuration/nuxt-config
Expand All @@ -28,14 +28,7 @@ export default defineNuxtConfig({
},

// build modules
modules: [
"@vueuse/nuxt",
"@nuxtjs/i18n-edge",
"@element-plus/nuxt",
"@nuxtjs/color-mode",
"@pinia/nuxt",
"@nuxt/image",
],
modules: ["@vueuse/nuxt", "@nuxtjs/i18n", "@element-plus/nuxt", "@nuxtjs/color-mode", "@pinia/nuxt", "@nuxt/image"],

// vueuse
vueuse: {
Expand All @@ -58,7 +51,7 @@ export default defineNuxtConfig({
define: {
"process.env.DEV_MODE": `"${isDev}"`,
"process.env.APP_BASE": `"${appBase}"`,
"process.env.SSR": `"false"`,
"process.env.SSR": `"true"`,
},
plugins: [],
},
Expand All @@ -69,14 +62,6 @@ export default defineNuxtConfig({
themes: ["dark"],
},

// https://nuxt.com/docs/guide/going-further/custom-routing#hash-mode-spa
ssr: false,
router: {
options: {
hashMode: true,
},
},

css: ["~/assets/siyuan/style.styl", "~/assets/siyuan/index.styl"],

app: {
Expand Down Expand Up @@ -127,17 +112,12 @@ export default defineNuxtConfig({

// 环境变量
runtimeConfig: {
// siyuanAuthToken: process.env.NUXT_SIYUAN_AUTH_TOKEN,
siyuanAuthToken: "",
// siyuanCookie: process.env.NUXT_SIYUAN_COOKIE,
siyuanCookie: "",
siyuanAuthToken: process.env.NUXT_SIYUAN_AUTH_TOKEN,
siyuanCookie: process.env.NUXT_SIYUAN_COOKIE,
public: {
// defaultType: process.env.NUXT_PUBLIC_DEFAULT_TYPE,
defaultType: "siyuan",
// siyuanApiUrl: process.env.NUXT_PUBLIC_SIYUAN_API_URL,
siyuanApiUrl: "",
// waitTime: process.env.NUXT_PUBLIC_WAIT_TIME,
waitTime: "0",
defaultType: process.env.NUXT_PUBLIC_DEFAULT_TYPE ?? "siyuan",
siyuanApiUrl: process.env.NUXT_PUBLIC_SIYUAN_API_URL ?? "http://127.0.0.1:6806",
waitTime: process.env.NUXT_PUBLIC_WAIT_TIME,
},
},
})
12 changes: 12 additions & 0 deletions plugins/07.domparser.client.ts
Expand Up @@ -58,6 +58,18 @@ export default defineNuxtPlugin(({ vueApp }) => {
`<symbol id="iconDot" viewBox="0 0 32 32">
<path d="M22.286 16c0 3.471-2.814 6.286-6.286 6.286s-6.286-2.814-6.286-6.286c0-3.471 2.814-6.286 6.286-6.286s6.286 2.814 6.286 6.286z"></path>
</symbol>`,
// 代码块复制按钮
`<symbol id="iconCopy" viewBox="0 0 32 32">
<path d="M22.545-0h-17.455c-1.6 0-2.909 1.309-2.909 2.909v20.364h2.909v-20.364h17.455v-2.909zM26.909 5.818h-16c-1.6 0-2.909 1.309-2.909 2.909v20.364c0 1.6 1.309 2.909 2.909 2.909h16c1.6 0 2.909-1.309 2.909-2.909v-20.364c0-1.6-1.309-2.909-2.909-2.909zM26.909 29.091h-16v-20.364h16v20.364z"></path>
</symbol>`,
// 代码块更多
`<symbol id="iconMore" viewBox="0 0 32 32">
<path d="M16 10.667c1.467 0 2.667-1.2 2.667-2.667s-1.2-2.667-2.667-2.667-2.667 1.2-2.667 2.667 1.2 2.667 2.667 2.667zM16 13.333c-1.467 0-2.667 1.2-2.667 2.667s1.2 2.667 2.667 2.667 2.667-1.2 2.667-2.667-1.2-2.667-2.667-2.667zM16 21.333c-1.467 0-2.667 1.2-2.667 2.667s1.2 2.667 2.667 2.667 2.667-1.2 2.667-2.667-1.2-2.667-2.667-2.667z"></path>
</symbol>`,
// 语言
`<symbol id="iconLanguage" viewBox="0 0 32 32">
<path d="M22.986 19.23h5.408q0.451-2.103 0.451-3.23t-0.451-3.23h-5.408q0.225 1.577 0.225 3.23t-0.225 3.23zM20.131 28.094q1.878-0.601 3.906-2.291t3.080-3.418h-4.732q-0.751 3.005-2.254 5.709zM19.756 19.23q0.225-1.577 0.225-3.23t-0.225-3.23h-7.512q-0.225 1.577-0.225 3.23t0.225 3.23h7.512zM16 28.77q2.103-3.080 3.080-6.385h-6.16q0.977 3.305 3.080 6.385zM9.615 9.615q0.901-3.23 2.254-5.709-1.878 0.601-3.944 2.291t-3.042 3.418h4.732zM4.883 22.385q0.977 1.728 3.042 3.418t3.944 2.291q-1.502-2.704-2.254-5.709h-4.732zM3.606 19.23h5.408q-0.225-1.577-0.225-3.23t0.225-3.23h-5.408q-0.451 2.103-0.451 3.23t0.451 3.23zM16 3.23q-2.103 3.080-3.080 6.385h6.16q-0.977-3.305-3.080-6.385zM27.117 9.615q-1.052-1.728-3.080-3.418t-3.906-2.291q1.352 2.479 2.254 5.709h4.732zM16 0q6.61 0 11.305 4.695t4.695 11.305-4.695 11.305-11.305 4.695-11.305-4.695-4.695-11.305 4.695-11.305 11.305-4.695z"></path>
</symbol>`,
])

// block ref links
Expand Down
4 changes: 4 additions & 0 deletions plugins/09.domparser.static.client.ts
Expand Up @@ -66,6 +66,10 @@ export default defineNuxtPlugin(({ vueApp }) => {
`<symbol id="iconMore" viewBox="0 0 32 32">
<path d="M16 10.667c1.467 0 2.667-1.2 2.667-2.667s-1.2-2.667-2.667-2.667-2.667 1.2-2.667 2.667 1.2 2.667 2.667 2.667zM16 13.333c-1.467 0-2.667 1.2-2.667 2.667s1.2 2.667 2.667 2.667 2.667-1.2 2.667-2.667-1.2-2.667-2.667-2.667zM16 21.333c-1.467 0-2.667 1.2-2.667 2.667s1.2 2.667 2.667 2.667 2.667-1.2 2.667-2.667-1.2-2.667-2.667-2.667z"></path>
</symbol>`,
// 语言
`<symbol id="iconLanguage" viewBox="0 0 32 32">
<path d="M22.986 19.23h5.408q0.451-2.103 0.451-3.23t-0.451-3.23h-5.408q0.225 1.577 0.225 3.23t-0.225 3.23zM20.131 28.094q1.878-0.601 3.906-2.291t3.080-3.418h-4.732q-0.751 3.005-2.254 5.709zM19.756 19.23q0.225-1.577 0.225-3.23t-0.225-3.23h-7.512q-0.225 1.577-0.225 3.23t0.225 3.23h7.512zM16 28.77q2.103-3.080 3.080-6.385h-6.16q0.977 3.305 3.080 6.385zM9.615 9.615q0.901-3.23 2.254-5.709-1.878 0.601-3.944 2.291t-3.042 3.418h4.732zM4.883 22.385q0.977 1.728 3.042 3.418t3.944 2.291q-1.502-2.704-2.254-5.709h-4.732zM3.606 19.23h5.408q-0.225-1.577-0.225-3.23t0.225-3.23h-5.408q-0.451 2.103-0.451 3.23t0.451 3.23zM16 3.23q-2.103 3.080-3.080 6.385h6.16q-0.977-3.305-3.080-6.385zM27.117 9.615q-1.052-1.728-3.080-3.418t-3.906-2.291q1.352 2.479 2.254 5.709h4.732zM16 0q6.61 0 11.305 4.695t4.695 11.305-4.695 11.305-11.305 4.695-11.305-4.695-4.695-11.305 4.695-11.305 11.305-4.695z"></path>
</symbol>`,
])

// block ref links
Expand Down
13 changes: 8 additions & 5 deletions plugins/renderer/useClientFormulate.ts
Expand Up @@ -9,11 +9,14 @@ const useClientFormulate = () => {

const renderFormulate = (el: HTMLElement) => {
// 内联公式
const inlineMathElement = document.querySelector('span[data-type="inline-math"][data-subtype="math"]')
if (inlineMathElement) {
const inlineContentValue = inlineMathElement.getAttribute("data-content")
win.katex.render(inlineContentValue, inlineMathElement, {
throwOnError: false,
const inlineMathElements = document.querySelectorAll('span[data-type="inline-math"][data-subtype="math"]')
console.log(inlineMathElements)
if (inlineMathElements) {
inlineMathElements.forEach((inlineMathElement) => {
const inlineContentValue = inlineMathElement.getAttribute("data-content")
win.katex.render(inlineContentValue, inlineMathElement, {
throwOnError: false,
})
})
}
// 替换
Expand Down

0 comments on commit ea32c03

Please sign in to comment.