@lark-apaas/fullstack-rspack-preset 1.0.22 → 1.0.23

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.
@@ -4,12 +4,14 @@ interface OgMetaInjectionPluginOptions {
4
4
  placeholder: string;
5
5
  }>;
6
6
  titlePlaceholder?: string;
7
+ descriptionPlaceholder?: string;
7
8
  faviconPlaceholder?: string;
8
9
  }
9
10
  declare class OgMetaInjectionPlugin {
10
11
  private options;
11
12
  private defaultOgTags;
12
13
  private defaultTitlePlaceholder;
14
+ private defaultDescriptionPlaceholder;
13
15
  private defaultFaviconPlaceholder;
14
16
  constructor(options?: OgMetaInjectionPluginOptions);
15
17
  apply(compiler: any): void;
@@ -11,6 +11,8 @@ class OgMetaInjectionPlugin {
11
11
  ];
12
12
  // 默认 title 占位符
13
13
  this.defaultTitlePlaceholder = '{{appName}}';
14
+ // 默认 description 占位符
15
+ this.defaultDescriptionPlaceholder = '{{appDescription}}';
14
16
  // 默认 favicon 占位符
15
17
  this.defaultFaviconPlaceholder = '{{appAvatar}}';
16
18
  this.options = options || {};
@@ -77,6 +79,23 @@ class OgMetaInjectionPlugin {
77
79
  const newTitleTag = `\n <title>${titlePlaceholder}</title>`;
78
80
  html = html.replace('</head>', `${newTitleTag}\n </head>`);
79
81
  }
82
+ // 2.1 处理 <meta name="description"> 标签
83
+ const descriptionPlaceholder = this.options.descriptionPlaceholder ||
84
+ this.defaultDescriptionPlaceholder;
85
+ const descriptionMetaRegex = /<meta\b[^>]*\bname=["']description["'][^>]*>/i;
86
+ const descriptionMetaReplaceRegex = /<meta\b[^>]*\bname=["']description["'][^>]*>/gi;
87
+ if (descriptionMetaRegex.test(html)) {
88
+ html = html.replace(descriptionMetaReplaceRegex, (metaTag) => {
89
+ if (/\bcontent=/.test(metaTag)) {
90
+ return metaTag.replace(/\bcontent=(["'])([\s\S]*?)\1/i, `content="${descriptionPlaceholder}"`);
91
+ }
92
+ return metaTag.replace(/>$/, ` content="${descriptionPlaceholder}">`);
93
+ });
94
+ }
95
+ else {
96
+ const newDescriptionTag = `\n <meta name="description" content="${descriptionPlaceholder}">`;
97
+ html = html.replace('</head>', `${newDescriptionTag}\n </head>`);
98
+ }
80
99
  // 3. 处理 <link rel="icon"> 标签
81
100
  const faviconPlaceholder = this.options.faviconPlaceholder || this.defaultFaviconPlaceholder;
82
101
  const iconRegex = /<link\s+[^>]*rel=["']?(?:icon|shortcut icon)["']?[^>]*>/i;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-rspack-preset",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "files": [
5
5
  "lib",
6
6
  "patches",