@quartz-community/og-image 1.0.0 → 1.1.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5352988: Add a `useGeneratedDescription` option (default `true`). Set it to `false` to show `defaultDescription` on pages without a frontmatter description, instead of the excerpt the description plugin generates (jackyzha0/quartz#2470). An empty generated description now also falls back to `defaultDescription`.
8
+
3
9
  ## 1.0.0
4
10
 
5
11
  ### Major Changes
package/dist/index.d.ts CHANGED
@@ -36,7 +36,14 @@ type SocialImageOptions = {
36
36
  width: number;
37
37
  excludeRoot: boolean;
38
38
  defaultTitle?: string;
39
+ /** Shown when a page has no description of its own (see `useGeneratedDescription`). */
39
40
  defaultDescription?: string;
41
+ /**
42
+ * Use the description another plugin generated for the page (the description plugin's
43
+ * excerpt of its content) when the frontmatter has none. `false` skips it, so pages without
44
+ * a frontmatter `socialDescription` or `description` show `defaultDescription`. Default `true`.
45
+ */
46
+ useGeneratedDescription?: boolean;
40
47
  readingTimeText?: (minutes: number) => string;
41
48
  imageStructure: (options: ImageOptions & {
42
49
  userOpts: UserOpts;
package/dist/index.js CHANGED
@@ -24339,6 +24339,7 @@ var defaultOptions = {
24339
24339
  excludeRoot: false,
24340
24340
  defaultTitle: "Untitled",
24341
24341
  defaultDescription: "No description provided",
24342
+ useGeneratedDescription: true,
24342
24343
  readingTimeText: (minutes) => `${minutes} min read`
24343
24344
  };
24344
24345
  async function generateSocialImage({ cfg, description, fonts, title, fileData }, userOpts) {
@@ -24373,13 +24374,19 @@ async function generateSocialImage({ cfg, description, fonts, title, fileData },
24373
24374
  });
24374
24375
  return sharp(Buffer.from(svg)).webp({ quality: 40 });
24375
24376
  }
24377
+ function resolveDescription(fileData, opts) {
24378
+ const own2 = fileData.frontmatter?.socialDescription ?? fileData.frontmatter?.description;
24379
+ if (own2 != null) return own2;
24380
+ const generated = opts.useGeneratedDescription === false ? void 0 : fileData.description;
24381
+ return unescapeHTML(generated?.trim() || opts.defaultDescription || "");
24382
+ }
24376
24383
  async function processOgImage(ctx, fileData, fonts, fullOptions) {
24377
24384
  const cfg = ctx.cfg.configuration;
24378
24385
  const slug2 = fileData.slug;
24379
24386
  const titleSuffix = cfg.pageTitleSuffix ?? "";
24380
24387
  const frontmatter = fileData.frontmatter;
24381
24388
  const title = (frontmatter?.title ?? fullOptions.defaultTitle ?? "") + titleSuffix;
24382
- const description = frontmatter?.socialDescription ?? frontmatter?.description ?? unescapeHTML(fileData.description?.trim() ?? fullOptions.defaultDescription ?? "");
24389
+ const description = resolveDescription(fileData, fullOptions);
24383
24390
  const stream = await generateSocialImage(
24384
24391
  {
24385
24392
  title,