@sugarat/theme 0.1.41 → 0.1.42
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.d.ts +20 -4
- package/node.js +25 -9
- package/package.json +1 -1
- package/src/composables/config/blog.ts +1 -1
- package/src/composables/config/index.ts +20 -4
- package/src/utils/node/genFeed.ts +25 -6
- package/src/utils/node/mdPlugins.ts +15 -0
- package/src/utils/node/theme.ts +3 -3
package/node.d.ts
CHANGED
|
@@ -260,22 +260,38 @@ declare namespace Theme {
|
|
|
260
260
|
*/
|
|
261
261
|
RSS?: RSSOptions;
|
|
262
262
|
}
|
|
263
|
-
type RSSOptions = FeedOptions & {
|
|
263
|
+
type RSSOptions = Omit<FeedOptions, 'id'> & {
|
|
264
|
+
id?: string;
|
|
265
|
+
/**
|
|
266
|
+
* 你的站点地址
|
|
267
|
+
* @example 'https://sugarat.top'
|
|
268
|
+
*/
|
|
264
269
|
baseUrl: string;
|
|
265
270
|
/**
|
|
266
271
|
* 线上访问的RSS地址
|
|
272
|
+
* @default
|
|
273
|
+
* @example https://sugarat.top/feed.rss
|
|
274
|
+
* ```ts
|
|
275
|
+
* `${baseUrl + VPConfig.site.base + (filename || 'feed.rss'}`
|
|
276
|
+
* ```
|
|
267
277
|
*/
|
|
268
|
-
url
|
|
278
|
+
url?: string;
|
|
269
279
|
/**
|
|
270
280
|
* 输出的RSS文件名
|
|
271
281
|
* @default 'feed.rss'
|
|
272
282
|
*/
|
|
273
283
|
filename?: string;
|
|
274
284
|
/**
|
|
275
|
-
*
|
|
285
|
+
* RSS的图标展示
|
|
276
286
|
* @default true
|
|
277
287
|
*/
|
|
278
|
-
|
|
288
|
+
icon?: boolean;
|
|
289
|
+
/**
|
|
290
|
+
* 限制输出文件包含的文章数量
|
|
291
|
+
* @default 0
|
|
292
|
+
* @description (0 不限制;> 1 会按照日期排序对输出内容进行调整)
|
|
293
|
+
*/
|
|
294
|
+
limit?: number;
|
|
279
295
|
};
|
|
280
296
|
interface Config extends DefaultTheme.Config {
|
|
281
297
|
blog?: BlogConfig;
|
package/node.js
CHANGED
|
@@ -352,6 +352,11 @@ function supportRunExtendsPlugin(config) {
|
|
|
352
352
|
markdownExtendsConfigOriginal?.(...rest);
|
|
353
353
|
};
|
|
354
354
|
}
|
|
355
|
+
const inlineConfig = config.extends;
|
|
356
|
+
if (inlineConfig.themeConfig?.blog?.RSS && inlineConfig.themeConfig?.blog?.RSS?.icon !== false && inlineConfig.themeConfig?.socialLinks?.length && !inlineConfig.themeConfig?.socialLinks?.[0].link) {
|
|
357
|
+
const { RSS } = inlineConfig.themeConfig?.blog;
|
|
358
|
+
inlineConfig.themeConfig.socialLinks[0].link = `${RSS.baseUrl}${(config.base || "/") + (RSS.filename || "feed.rss")}`;
|
|
359
|
+
}
|
|
355
360
|
}
|
|
356
361
|
|
|
357
362
|
// src/utils/node/theme.ts
|
|
@@ -430,13 +435,13 @@ function getArticles(cfg) {
|
|
|
430
435
|
}
|
|
431
436
|
function patchVPThemeConfig(cfg, vpThemeConfig = {}) {
|
|
432
437
|
const RSS = cfg?.RSS;
|
|
433
|
-
if (RSS && RSS.
|
|
438
|
+
if (RSS && RSS.icon !== false) {
|
|
434
439
|
vpThemeConfig.socialLinks = [
|
|
435
440
|
{
|
|
436
441
|
icon: {
|
|
437
442
|
svg: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 448 512"><path d="M400 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h352c26.51 0 48-21.49 48-48V80c0-26.51-21.49-48-48-48zM112 416c-26.51 0-48-21.49-48-48s21.49-48 48-48s48 21.49 48 48s-21.49 48-48 48zm157.533 0h-34.335c-6.011 0-11.051-4.636-11.442-10.634c-5.214-80.05-69.243-143.92-149.123-149.123c-5.997-.39-10.633-5.431-10.633-11.441v-34.335c0-6.535 5.468-11.777 11.994-11.425c110.546 5.974 198.997 94.536 204.964 204.964c.352 6.526-4.89 11.994-11.425 11.994zm103.027 0h-34.334c-6.161 0-11.175-4.882-11.427-11.038c-5.598-136.535-115.204-246.161-251.76-251.76C68.882 152.949 64 147.935 64 141.774V107.44c0-6.454 5.338-11.664 11.787-11.432c167.83 6.025 302.21 141.191 308.205 308.205c.232 6.449-4.978 11.787-11.432 11.787z" fill="currentColor"></path></svg>'
|
|
438
443
|
},
|
|
439
|
-
link: RSS
|
|
444
|
+
link: RSS?.url
|
|
440
445
|
}
|
|
441
446
|
];
|
|
442
447
|
}
|
|
@@ -454,7 +459,7 @@ var import_fs2 = __toESM(require("fs"));
|
|
|
454
459
|
var import_feed = require("feed");
|
|
455
460
|
async function genFeed(config) {
|
|
456
461
|
const blogCfg = config.userConfig.themeConfig.blog;
|
|
457
|
-
|
|
462
|
+
let posts = blogCfg.pagesData;
|
|
458
463
|
const { RSS, authorList = [] } = blogCfg;
|
|
459
464
|
if (!RSS)
|
|
460
465
|
return;
|
|
@@ -469,14 +474,20 @@ async function genFeed(config) {
|
|
|
469
474
|
console.log("=== feed: https://github.com/jpmonette/feed ===");
|
|
470
475
|
const { base } = config.userConfig;
|
|
471
476
|
const { baseUrl, filename } = RSS;
|
|
472
|
-
const feed = new import_feed.Feed(
|
|
477
|
+
const feed = new import_feed.Feed({
|
|
478
|
+
id: baseUrl,
|
|
479
|
+
link: baseUrl,
|
|
480
|
+
...RSS
|
|
481
|
+
});
|
|
473
482
|
posts.sort(
|
|
474
483
|
(a, b) => +new Date(b.meta.date) - +new Date(a.meta.date)
|
|
475
484
|
);
|
|
485
|
+
posts = posts.filter((v) => v.meta.layout !== "home").filter((v) => v.meta.hidden !== true);
|
|
486
|
+
if (void 0 !== RSS?.limit && RSS?.limit > 0) {
|
|
487
|
+
posts.splice(RSS.limit);
|
|
488
|
+
}
|
|
476
489
|
for (const { route, meta } of posts) {
|
|
477
|
-
const { title, description, date
|
|
478
|
-
if (hidden)
|
|
479
|
-
continue;
|
|
490
|
+
const { title, description, date } = meta;
|
|
480
491
|
const author = meta.author ?? blogCfg.author;
|
|
481
492
|
let link = `${baseUrl}${withBase(
|
|
482
493
|
base || "",
|
|
@@ -505,9 +516,14 @@ async function genFeed(config) {
|
|
|
505
516
|
date: new Date(date)
|
|
506
517
|
});
|
|
507
518
|
}
|
|
508
|
-
const
|
|
519
|
+
const RSSFilename = filename || "feed.rss";
|
|
520
|
+
const RSSFile = import_path2.default.join(config.outDir, RSSFilename);
|
|
509
521
|
(0, import_fs2.writeFileSync)(RSSFile, feed.rss2());
|
|
510
|
-
console.log("\u{1F389} RSS generated",
|
|
522
|
+
console.log("\u{1F389} RSS generated", RSSFilename);
|
|
523
|
+
console.log("rss filepath:", RSSFile);
|
|
524
|
+
console.log("rss url:", `${baseUrl}${config.site.base + RSSFilename}`);
|
|
525
|
+
console.log("include", posts.length, "posts");
|
|
526
|
+
console.log();
|
|
511
527
|
console.log();
|
|
512
528
|
}
|
|
513
529
|
|
package/package.json
CHANGED
|
@@ -141,7 +141,7 @@ export function useActiveAnchor() {
|
|
|
141
141
|
onMounted(() => {
|
|
142
142
|
const { hash } = window.location
|
|
143
143
|
if (hash) {
|
|
144
|
-
el.value = document.querySelector(decodeURIComponent(hash))
|
|
144
|
+
el.value = document.querySelector(decodeURIComponent(hash)) as any
|
|
145
145
|
}
|
|
146
146
|
})
|
|
147
147
|
return el
|
|
@@ -281,22 +281,38 @@ export namespace Theme {
|
|
|
281
281
|
RSS?: RSSOptions
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
export type RSSOptions = FeedOptions & {
|
|
284
|
+
export type RSSOptions = Omit<FeedOptions, 'id'> & {
|
|
285
|
+
id?: string
|
|
286
|
+
/**
|
|
287
|
+
* 你的站点地址
|
|
288
|
+
* @example 'https://sugarat.top'
|
|
289
|
+
*/
|
|
285
290
|
baseUrl: string
|
|
286
291
|
/**
|
|
287
292
|
* 线上访问的RSS地址
|
|
293
|
+
* @default
|
|
294
|
+
* @example https://sugarat.top/feed.rss
|
|
295
|
+
* ```ts
|
|
296
|
+
* `${baseUrl + VPConfig.site.base + (filename || 'feed.rss'}`
|
|
297
|
+
* ```
|
|
288
298
|
*/
|
|
289
|
-
url
|
|
299
|
+
url?: string
|
|
290
300
|
/**
|
|
291
301
|
* 输出的RSS文件名
|
|
292
302
|
* @default 'feed.rss'
|
|
293
303
|
*/
|
|
294
304
|
filename?: string
|
|
295
305
|
/**
|
|
296
|
-
*
|
|
306
|
+
* RSS的图标展示
|
|
297
307
|
* @default true
|
|
298
308
|
*/
|
|
299
|
-
|
|
309
|
+
icon?: boolean
|
|
310
|
+
/**
|
|
311
|
+
* 限制输出文件包含的文章数量
|
|
312
|
+
* @default 0
|
|
313
|
+
* @description (0 不限制;> 1 会按照日期排序对输出内容进行调整)
|
|
314
|
+
*/
|
|
315
|
+
limit?: number
|
|
300
316
|
}
|
|
301
317
|
export interface Config extends DefaultTheme.Config {
|
|
302
318
|
blog?: BlogConfig
|
|
@@ -9,7 +9,7 @@ import { pageMap } from './theme'
|
|
|
9
9
|
|
|
10
10
|
export async function genFeed(config: SiteConfig) {
|
|
11
11
|
const blogCfg: Theme.BlogConfig = config.userConfig.themeConfig.blog
|
|
12
|
-
|
|
12
|
+
let posts: Theme.PageData[] = blogCfg.pagesData
|
|
13
13
|
const { RSS, authorList = [] } = blogCfg
|
|
14
14
|
if (!RSS) return
|
|
15
15
|
const { createMarkdownRenderer } = await import('vitepress')
|
|
@@ -25,16 +25,30 @@ export async function genFeed(config: SiteConfig) {
|
|
|
25
25
|
const { base } = config.userConfig
|
|
26
26
|
|
|
27
27
|
const { baseUrl, filename } = RSS
|
|
28
|
-
const feed = new Feed(
|
|
28
|
+
const feed = new Feed({
|
|
29
|
+
id: baseUrl,
|
|
30
|
+
link: baseUrl,
|
|
31
|
+
...RSS
|
|
32
|
+
})
|
|
29
33
|
|
|
30
34
|
posts.sort(
|
|
31
35
|
(a, b) =>
|
|
32
36
|
+new Date(b.meta.date as string) - +new Date(a.meta.date as string)
|
|
33
37
|
)
|
|
34
38
|
|
|
39
|
+
posts = posts
|
|
40
|
+
// 过滤掉 layout:home
|
|
41
|
+
.filter((v) => v.meta.layout !== 'home')
|
|
42
|
+
// 过滤掉不展示的
|
|
43
|
+
.filter((v) => v.meta.hidden !== true)
|
|
44
|
+
|
|
45
|
+
if (undefined !== RSS?.limit && RSS?.limit > 0) {
|
|
46
|
+
posts.splice(RSS.limit)
|
|
47
|
+
}
|
|
48
|
+
|
|
35
49
|
for (const { route, meta } of posts) {
|
|
36
|
-
const { title, description, date
|
|
37
|
-
|
|
50
|
+
const { title, description, date } = meta
|
|
51
|
+
|
|
38
52
|
const author = meta.author ?? blogCfg.author
|
|
39
53
|
let link = `${baseUrl}${withBase(
|
|
40
54
|
base || '',
|
|
@@ -68,8 +82,13 @@ export async function genFeed(config: SiteConfig) {
|
|
|
68
82
|
date: new Date(date)
|
|
69
83
|
})
|
|
70
84
|
}
|
|
71
|
-
const
|
|
85
|
+
const RSSFilename = filename || 'feed.rss'
|
|
86
|
+
const RSSFile = path.join(config.outDir, RSSFilename)
|
|
72
87
|
writeFileSync(RSSFile, feed.rss2())
|
|
73
|
-
console.log('🎉 RSS generated',
|
|
88
|
+
console.log('🎉 RSS generated', RSSFilename)
|
|
89
|
+
console.log('rss filepath:', RSSFile)
|
|
90
|
+
console.log('rss url:', `${baseUrl}${config.site.base + RSSFilename}`)
|
|
91
|
+
console.log('include', posts.length, 'posts')
|
|
92
|
+
console.log()
|
|
74
93
|
console.log()
|
|
75
94
|
}
|
|
@@ -92,4 +92,19 @@ export function supportRunExtendsPlugin(config: UserConfig<Theme.Config>) {
|
|
|
92
92
|
markdownExtendsConfigOriginal?.(...rest)
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
+
|
|
96
|
+
// 特殊处理RSS,自动生成url(未来统一维护到 RSS插件里,待下一版主题架构升级)
|
|
97
|
+
const inlineConfig = config.extends as UserConfig<Theme.Config>
|
|
98
|
+
|
|
99
|
+
if (
|
|
100
|
+
inlineConfig.themeConfig?.blog?.RSS &&
|
|
101
|
+
inlineConfig.themeConfig?.blog?.RSS?.icon !== false &&
|
|
102
|
+
inlineConfig.themeConfig?.socialLinks?.length &&
|
|
103
|
+
!inlineConfig.themeConfig?.socialLinks?.[0].link
|
|
104
|
+
) {
|
|
105
|
+
const { RSS } = inlineConfig.themeConfig?.blog
|
|
106
|
+
inlineConfig.themeConfig.socialLinks[0].link = `${RSS.baseUrl}${
|
|
107
|
+
(config.base || '/') + (RSS.filename || 'feed.rss')
|
|
108
|
+
}`
|
|
109
|
+
}
|
|
95
110
|
}
|
package/src/utils/node/theme.ts
CHANGED
|
@@ -127,15 +127,15 @@ export function patchVPThemeConfig(
|
|
|
127
127
|
cfg?: Partial<Theme.BlogConfig>,
|
|
128
128
|
vpThemeConfig: any = {}
|
|
129
129
|
) {
|
|
130
|
-
// 添加 icon
|
|
130
|
+
// 添加 RSS icon
|
|
131
131
|
const RSS = cfg?.RSS
|
|
132
|
-
if (RSS && RSS.
|
|
132
|
+
if (RSS && RSS.icon !== false) {
|
|
133
133
|
vpThemeConfig.socialLinks = [
|
|
134
134
|
{
|
|
135
135
|
icon: {
|
|
136
136
|
svg: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 448 512"><path d="M400 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h352c26.51 0 48-21.49 48-48V80c0-26.51-21.49-48-48-48zM112 416c-26.51 0-48-21.49-48-48s21.49-48 48-48s48 21.49 48 48s-21.49 48-48 48zm157.533 0h-34.335c-6.011 0-11.051-4.636-11.442-10.634c-5.214-80.05-69.243-143.92-149.123-149.123c-5.997-.39-10.633-5.431-10.633-11.441v-34.335c0-6.535 5.468-11.777 11.994-11.425c110.546 5.974 198.997 94.536 204.964 204.964c.352 6.526-4.89 11.994-11.425 11.994zm103.027 0h-34.334c-6.161 0-11.175-4.882-11.427-11.038c-5.598-136.535-115.204-246.161-251.76-251.76C68.882 152.949 64 147.935 64 141.774V107.44c0-6.454 5.338-11.664 11.787-11.432c167.83 6.025 302.21 141.191 308.205 308.205c.232 6.449-4.978 11.787-11.432 11.787z" fill="currentColor"></path></svg>'
|
|
137
137
|
},
|
|
138
|
-
link: RSS
|
|
138
|
+
link: RSS?.url
|
|
139
139
|
}
|
|
140
140
|
]
|
|
141
141
|
}
|