@sugarat/theme 0.1.40 → 0.1.41

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.
package/node.js CHANGED
@@ -369,6 +369,7 @@ function patchDefaultThemeSideBar(cfg) {
369
369
  ]
370
370
  } : void 0;
371
371
  }
372
+ var pageMap = /* @__PURE__ */ new Map();
372
373
  function getArticles(cfg) {
373
374
  const srcDir = cfg?.srcDir || process.argv.slice(2)?.[1] || ".";
374
375
  const files = import_fast_glob.default.sync(`${srcDir}/**/*.md`, { ignore: ["node_modules"] });
@@ -389,9 +390,13 @@ function getArticles(cfg) {
389
390
  ""
390
391
  );
391
392
  }
393
+ pageMap.set(`/${route}`, v);
392
394
  const fileContent = import_fs.default.readFileSync(v, "utf-8");
395
+ const { data: frontmatter, excerpt } = (0, import_gray_matter.default)(fileContent, {
396
+ excerpt: true
397
+ });
393
398
  const meta = {
394
- ...(0, import_gray_matter.default)(fileContent).data
399
+ ...frontmatter
395
400
  };
396
401
  if (!meta.title) {
397
402
  meta.title = getDefaultTitle(fileContent);
@@ -445,14 +450,21 @@ var import_child_process2 = require("child_process");
445
450
 
446
451
  // src/utils/node/genFeed.ts
447
452
  var import_path2 = __toESM(require("path"));
448
- var import_fs2 = require("fs");
453
+ var import_fs2 = __toESM(require("fs"));
449
454
  var import_feed = require("feed");
450
- function genFeed(config) {
455
+ async function genFeed(config) {
451
456
  const blogCfg = config.userConfig.themeConfig.blog;
452
457
  const posts = blogCfg.pagesData;
453
458
  const { RSS, authorList = [] } = blogCfg;
454
459
  if (!RSS)
455
460
  return;
461
+ const { createMarkdownRenderer } = await import("vitepress");
462
+ const mdRender = await createMarkdownRenderer(
463
+ config.srcDir,
464
+ config.markdown,
465
+ config.site.base,
466
+ config.logger
467
+ );
456
468
  console.log();
457
469
  console.log("=== feed: https://github.com/jpmonette/feed ===");
458
470
  const { base } = config.userConfig;
@@ -466,13 +478,24 @@ function genFeed(config) {
466
478
  if (hidden)
467
479
  continue;
468
480
  const author = meta.author ?? blogCfg.author;
469
- const link = `${baseUrl}${withBase(base || "", route)}.html`;
481
+ let link = `${baseUrl}${withBase(
482
+ base || "",
483
+ route.replace(/(^|\/)index$/, "$1")
484
+ )}`;
485
+ link = link.endsWith("/") ? link : `${link}${config?.cleanUrls ? "" : ".html"}`;
470
486
  const authorLink = authorList.find((v) => v.nickname === author)?.url;
487
+ let html;
488
+ const filepath = pageMap.get(route);
489
+ if (filepath) {
490
+ const fileContent = import_fs2.default.readFileSync(filepath, "utf-8");
491
+ html = mdRender.render(fileContent);
492
+ }
471
493
  feed.addItem({
472
494
  title,
473
495
  id: link,
474
496
  link,
475
497
  description,
498
+ content: html,
476
499
  author: [
477
500
  {
478
501
  name: author,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarat/theme",
3
- "version": "0.1.40",
3
+ "version": "0.1.41",
4
4
  "description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -58,10 +58,10 @@
58
58
  "scripts": {
59
59
  "dev": "npm run build:node && npm run dev:docs",
60
60
  "dev:docs": "vitepress dev docs",
61
- "dev:node": "npx tsup src/node.ts --dts --out-dir=./ --watch",
61
+ "dev:node": "npx tsup src/node.ts --dts --out-dir=./ --watch --external vitepress",
62
62
  "build": "npm run build:node && npm run build:docs",
63
63
  "build:docs": "vitepress build docs",
64
- "build:node": "npx tsup src/node.ts --dts --out-dir=./",
64
+ "build:node": "npx tsup src/node.ts --dts --out-dir=./ --external vitepress",
65
65
  "serve": "vitepress serve docs"
66
66
  }
67
67
  }
@@ -1,16 +1,25 @@
1
1
  /* eslint-disable no-console */
2
2
  import path from 'path'
3
- import { writeFileSync } from 'fs'
3
+ import fs, { writeFileSync } from 'fs'
4
4
  import { Feed } from 'feed'
5
5
  import type { SiteConfig } from 'vitepress'
6
6
  import type { Theme } from '../../composables/config/index'
7
7
  import { withBase } from './index'
8
+ import { pageMap } from './theme'
8
9
 
9
- export function genFeed(config: SiteConfig) {
10
+ export async function genFeed(config: SiteConfig) {
10
11
  const blogCfg: Theme.BlogConfig = config.userConfig.themeConfig.blog
11
12
  const posts: Theme.PageData[] = blogCfg.pagesData
12
13
  const { RSS, authorList = [] } = blogCfg
13
14
  if (!RSS) return
15
+ const { createMarkdownRenderer } = await import('vitepress')
16
+
17
+ const mdRender = await createMarkdownRenderer(
18
+ config.srcDir,
19
+ config.markdown,
20
+ config.site.base,
21
+ config.logger
22
+ )
14
23
  console.log()
15
24
  console.log('=== feed: https://github.com/jpmonette/feed ===')
16
25
  const { base } = config.userConfig
@@ -27,16 +36,29 @@ export function genFeed(config: SiteConfig) {
27
36
  const { title, description, date, hidden } = meta
28
37
  if (hidden) continue
29
38
  const author = meta.author ?? blogCfg.author
30
- const link = `${baseUrl}${withBase(base || '', route)}.html`
39
+ let link = `${baseUrl}${withBase(
40
+ base || '',
41
+ // 移除末尾的index
42
+ route.replace(/(^|\/)index$/, '$1')
43
+ )}`
44
+ // 补全后缀
45
+ link = link.endsWith('/')
46
+ ? link
47
+ : `${link}${config?.cleanUrls ? '' : '.html'}`
31
48
  const authorLink = authorList.find((v) => v.nickname === author)?.url
49
+ let html
50
+ const filepath = pageMap.get(route)
51
+ if (filepath) {
52
+ const fileContent = fs.readFileSync(filepath, 'utf-8')
53
+ html = mdRender.render(fileContent)
54
+ }
55
+
32
56
  feed.addItem({
33
57
  title,
34
58
  id: link,
35
- // TODO: 待定,添加transform
36
59
  link,
37
60
  description,
38
- // TODO: 待定,文章多的时候,会导致 RSS 文件过大
39
- // content: html,
61
+ content: html,
40
62
  author: [
41
63
  {
42
64
  name: author,
@@ -20,6 +20,9 @@ export function patchDefaultThemeSideBar(cfg?: Partial<Theme.BlogConfig>) {
20
20
  : undefined
21
21
  }
22
22
 
23
+ // hack:RSS用
24
+ export const pageMap = new Map<string, string>()
25
+
23
26
  export function getArticles(cfg?: Partial<Theme.BlogConfig>) {
24
27
  const srcDir = cfg?.srcDir || process.argv.slice(2)?.[1] || '.'
25
28
  const files = glob.sync(`${srcDir}/**/*.md`, { ignore: ['node_modules'] })
@@ -51,11 +54,17 @@ export function getArticles(cfg?: Partial<Theme.BlogConfig>) {
51
54
  ''
52
55
  )
53
56
  }
57
+ // hack:RSS使用
58
+ pageMap.set(`/${route}`, v)
54
59
 
55
60
  const fileContent = fs.readFileSync(v, 'utf-8')
61
+ // TODO:摘要生成优化
62
+ const { data: frontmatter, excerpt } = matter(fileContent, {
63
+ excerpt: true
64
+ })
56
65
 
57
66
  const meta: Partial<Theme.PageMeta> = {
58
- ...matter(fileContent).data
67
+ ...frontmatter
59
68
  }
60
69
 
61
70
  if (!meta.title) {