@sugarat/theme 0.1.36-beta.1 → 0.1.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/node.js +34 -100
  2. package/package.json +5 -5
  3. package/src/node.ts +17 -21
package/node.js CHANGED
@@ -115,10 +115,10 @@ var ruleBlockTabs = (state, startLine, endLine, silent) => {
115
115
  var tabBreakRE = /^\s*::(.+)$/;
116
116
  var forbiddenCharsInSlotNames = /[ '"]/;
117
117
  var parseTabBreakLine = (line) => {
118
- const m2 = line.match(tabBreakRE);
119
- if (!m2)
118
+ const m = line.match(tabBreakRE);
119
+ if (!m)
120
120
  return null;
121
- const trimmed = m2[1].trim();
121
+ const trimmed = m[1].trim();
122
122
  if (forbiddenCharsInSlotNames.test(trimmed)) {
123
123
  throw new Error(
124
124
  `contains forbidden chars in slot names (space and quotes) (${JSON.stringify(
@@ -206,86 +206,24 @@ var tabsPlugin = (md) => {
206
206
  };
207
207
  };
208
208
 
209
- // ../../node_modules/.pnpm/vitepress-plugin-mermaid@2.0.13_mermaid@10.2.4_vitepress@1.0.0-beta.2/node_modules/vitepress-plugin-mermaid/dist/vitepress-plugin-mermaid.es.mjs
210
- var m = (e) => {
211
- const r = e.renderer.rules.fence.bind(e.renderer.rules);
212
- e.renderer.rules.fence = (a, i, t, s, o) => {
213
- const n = a[i];
214
- if (n.info.trim() === "mermaid")
215
- try {
216
- return `
217
- <Suspense>
218
- <template #default>
219
- <Mermaid id="mermaid-${i}" graph="${encodeURIComponent(
220
- n.content
221
- )}"></Mermaid>
222
- </template>
223
- <!-- loading state via #fallback slot -->
224
- <template #fallback>
225
- Loading...
226
- </template>
227
- </Suspense>`;
228
- } catch (l) {
229
- return `<pre>${l}</pre>`;
230
- }
231
- return n.info.trim() === "mmd" && (a[i].info = "mermaid"), r(a, i, t, s, o);
232
- };
233
- };
234
- var d = {
235
- securityLevel: "loose",
236
- startOnLoad: false
237
- };
238
- function p(e) {
239
- const r = {
240
- ...d,
241
- ...e
242
- }, a = "virtual:mermaid-config", i = "\0" + a;
243
- return {
244
- name: "vite-plugin-mermaid",
245
- enforce: "post",
246
- transform(t, s) {
247
- if (s.includes("vitepress/dist/client/app/index.js"))
248
- return t = `
249
- import Mermaid from 'vitepress-plugin-mermaid/Mermaid.vue';
250
- ` + t, t = t.replace(
251
- "// install global components",
252
- `// install global components
253
- app.component('Mermaid', Mermaid);
254
- `
255
- ), {
256
- code: t,
257
- map: null
258
- };
259
- },
260
- async resolveId(t) {
261
- if (t === a)
262
- return i;
263
- },
264
- async load(t) {
265
- if (t === i)
266
- return `export default ${JSON.stringify(r)};`;
267
- }
268
- };
269
- }
270
-
271
209
  // src/utils/index.ts
272
- function formatDate(d2, fmt = "yyyy-MM-dd hh:mm:ss") {
273
- if (!(d2 instanceof Date)) {
274
- d2 = new Date(d2);
210
+ function formatDate(d, fmt = "yyyy-MM-dd hh:mm:ss") {
211
+ if (!(d instanceof Date)) {
212
+ d = new Date(d);
275
213
  }
276
214
  const o = {
277
- "M+": d2.getMonth() + 1,
278
- "d+": d2.getDate(),
279
- "h+": d2.getHours(),
280
- "m+": d2.getMinutes(),
281
- "s+": d2.getSeconds(),
282
- "q+": Math.floor((d2.getMonth() + 3) / 3),
283
- S: d2.getMilliseconds()
215
+ "M+": d.getMonth() + 1,
216
+ "d+": d.getDate(),
217
+ "h+": d.getHours(),
218
+ "m+": d.getMinutes(),
219
+ "s+": d.getSeconds(),
220
+ "q+": Math.floor((d.getMonth() + 3) / 3),
221
+ S: d.getMilliseconds()
284
222
  };
285
223
  if (/(y+)/.test(fmt)) {
286
224
  fmt = fmt.replace(
287
225
  RegExp.$1,
288
- `${d2.getFullYear()}`.substr(4 - RegExp.$1.length)
226
+ `${d.getFullYear()}`.substr(4 - RegExp.$1.length)
289
227
  );
290
228
  }
291
229
  for (const k in o) {
@@ -414,7 +352,8 @@ function getThemeConfig(cfg) {
414
352
  cfg.mermaid = cfg?.mermaid ?? false;
415
353
  }
416
354
  if (cfg?.mermaid !== false) {
417
- markdownPlugin.push(m);
355
+ const { MermaidMarkdown } = require("vitepress-plugin-mermaid");
356
+ markdownPlugin.push(MermaidMarkdown);
418
357
  }
419
358
  if (markdownPlugin.length) {
420
359
  extraConfig.markdown = {
@@ -484,8 +423,8 @@ function getGitTimestamp(file) {
484
423
  return new Promise((resolve, reject) => {
485
424
  const child = (0, import_child_process.spawn)("git", ["log", "-1", '--pretty="%ci"', file]);
486
425
  let output = "";
487
- child.stdout.on("data", (d2) => {
488
- output += String(d2);
426
+ child.stdout.on("data", (d) => {
427
+ output += String(d);
489
428
  });
490
429
  child.on("close", () => {
491
430
  resolve(+new Date(output));
@@ -503,31 +442,26 @@ function assignMermaid(config) {
503
442
  config.vite = {};
504
443
  if (!config.vite.plugins)
505
444
  config.vite.plugins = [];
506
- config.vite.plugins.push(p(config.mermaid));
507
- if (!config.vite.optimizeDeps)
508
- config.vite.optimizeDeps = {};
509
- config.vite.optimizeDeps = {
510
- ...config.vite.optimizeDeps,
511
- include: [
512
- "@braintree/sanitize-url",
513
- "dayjs",
514
- "debug",
515
- "cytoscape-cose-bilkent",
516
- "cytoscape"
517
- ]
518
- };
445
+ const { MermaidPlugin } = require("vitepress-plugin-mermaid");
446
+ config.vite.plugins.push(MermaidPlugin(config.mermaid));
519
447
  if (!config.vite.resolve)
520
448
  config.vite.resolve = {};
521
449
  if (!config.vite.resolve.alias)
522
450
  config.vite.resolve.alias = {};
523
- config.vite.resolve.alias = {
524
- ...config.vite.resolve.alias,
525
- "dayjs/plugin/advancedFormat.js": "dayjs/esm/plugin/advancedFormat",
526
- "dayjs/plugin/customParseFormat.js": "dayjs/esm/plugin/customParseFormat",
527
- "dayjs/plugin/isoWeek.js": "dayjs/esm/plugin/isoWeek",
528
- "cytoscape/dist/cytoscape.umd.js": "cytoscape/dist/cytoscape.esm.js",
529
- mermaid: "mermaid/dist/mermaid.esm.mjs"
530
- };
451
+ config.vite.resolve.alias = [
452
+ ...aliasObjectToArray({
453
+ ...config.vite.resolve.alias,
454
+ "cytoscape/dist/cytoscape.umd.js": "cytoscape/dist/cytoscape.esm.js",
455
+ mermaid: "mermaid/dist/mermaid.esm.mjs"
456
+ }),
457
+ { find: /^dayjs\/(.*).js/, replacement: "dayjs/esm/$1" }
458
+ ];
459
+ }
460
+ function aliasObjectToArray(obj) {
461
+ return Object.entries(obj).map(([find, replacement]) => ({
462
+ find,
463
+ replacement
464
+ }));
531
465
  }
532
466
  function defineConfig(config) {
533
467
  if (config.themeConfig?.themeConfig) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarat/theme",
3
- "version": "0.1.36-beta.1",
3
+ "version": "0.1.36",
4
4
  "description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -39,12 +39,12 @@
39
39
  "fast-glob": "^3.2.12",
40
40
  "gray-matter": "^4.0.3",
41
41
  "highlight.js": "^11.7.0",
42
- "vue-command-palette": "^0.1.4"
43
- },
44
- "devDependencies": {
42
+ "vue-command-palette": "^0.1.4",
45
43
  "@mermaid-js/mermaid-mindmap": "^9.3.0",
46
44
  "mermaid": "^10.2.4",
47
- "vitepress-plugin-mermaid": "^2.0.13",
45
+ "vitepress-plugin-mermaid": "^2.0.13"
46
+ },
47
+ "devDependencies": {
48
48
  "@element-plus/icons-vue": "^2.1.0",
49
49
  "element-plus": "^2.3.4",
50
50
  "sass": "^1.56.1",
package/src/node.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable global-require */
1
2
  /* eslint-disable prefer-rest-params */
2
3
  import glob from 'fast-glob'
3
4
  import matter from 'gray-matter'
@@ -6,7 +7,6 @@ import { execSync, spawn, spawnSync } from 'child_process'
6
7
  import path from 'path'
7
8
  import type { SiteConfig, UserConfig } from 'vitepress'
8
9
  import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'
9
- import { MermaidMarkdown, MermaidPlugin } from 'vitepress-plugin-mermaid'
10
10
  import { formatDate } from './utils/index'
11
11
  import type { Theme } from './composables/config/index'
12
12
 
@@ -181,6 +181,7 @@ export function getThemeConfig(cfg?: Partial<Theme.BlogConfig>) {
181
181
  cfg.mermaid = cfg?.mermaid ?? false
182
182
  }
183
183
  if (cfg?.mermaid !== false) {
184
+ const { MermaidMarkdown } = require('vitepress-plugin-mermaid')
184
185
  markdownPlugin.push(MermaidMarkdown)
185
186
  // extraConfig.vite = {
186
187
  // ...extraConfig.vite,
@@ -321,31 +322,26 @@ export function assignMermaid(config: any) {
321
322
 
322
323
  if (!config.vite) config.vite = {}
323
324
  if (!config.vite.plugins) config.vite.plugins = []
325
+ const { MermaidPlugin } = require('vitepress-plugin-mermaid')
324
326
  config.vite.plugins.push(MermaidPlugin(config.mermaid))
325
- if (!config.vite.optimizeDeps) config.vite.optimizeDeps = {}
326
- config.vite.optimizeDeps = {
327
- ...config.vite.optimizeDeps,
328
- include: [
329
- '@braintree/sanitize-url',
330
- 'dayjs',
331
- 'debug',
332
- 'cytoscape-cose-bilkent',
333
- 'cytoscape'
334
- ]
335
- }
336
327
  if (!config.vite.resolve) config.vite.resolve = {}
337
328
  if (!config.vite.resolve.alias) config.vite.resolve.alias = {}
338
329
 
339
- config.vite.resolve.alias = {
340
- ...config.vite.resolve.alias,
341
- 'dayjs/plugin/advancedFormat.js': 'dayjs/esm/plugin/advancedFormat',
342
- 'dayjs/plugin/customParseFormat.js': 'dayjs/esm/plugin/customParseFormat',
343
- 'dayjs/plugin/isoWeek.js': 'dayjs/esm/plugin/isoWeek',
344
- 'cytoscape/dist/cytoscape.umd.js': 'cytoscape/dist/cytoscape.esm.js',
345
- mermaid: 'mermaid/dist/mermaid.esm.mjs'
346
- }
330
+ config.vite.resolve.alias = [
331
+ ...aliasObjectToArray({
332
+ ...config.vite.resolve.alias,
333
+ 'cytoscape/dist/cytoscape.umd.js': 'cytoscape/dist/cytoscape.esm.js',
334
+ mermaid: 'mermaid/dist/mermaid.esm.mjs'
335
+ }),
336
+ { find: /^dayjs\/(.*).js/, replacement: 'dayjs/esm/$1' }
337
+ ]
338
+ }
339
+ function aliasObjectToArray(obj: Record<string, string>) {
340
+ return Object.entries(obj).map(([find, replacement]) => ({
341
+ find,
342
+ replacement
343
+ }))
347
344
  }
348
-
349
345
  export function defineConfig(config: UserConfig<Theme.Config>): any {
350
346
  // 兼容低版本主题配置
351
347
  // @ts-ignore