@rathnasgala/theme 0.0.1 → 0.0.6

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.
@@ -1,6 +1,7 @@
1
- import { markdownLibrary } from '../lib/render-markdown.js';
1
+ import { renderMarkdownDocument } from '../lib/render-markdown.js';
2
2
  import { articleHreflang, postSeo } from '../lib/seo.js';
3
3
  import { engagementFor } from '../lib/engagement-snapshot.js';
4
+ import { resolveShareTargets } from '../lib/share-targets.js';
4
5
 
5
6
  export default class ValidatedPostPages {
6
7
  data() {
@@ -19,8 +20,19 @@ export default class ValidatedPostPages {
19
20
  return articleHreflang(buildManifest.posts, site).get(post.source) ?? [];
20
21
  },
21
22
  engagement: ({ engagementSnapshot, post }) => engagementFor(engagementSnapshot, post.id),
23
+ shareTargets: ({ post, site }) => post?.publicationState === 'published'
24
+ ? resolveShareTargets({
25
+ configured: site.sharing.targets,
26
+ title: post.frontmatter.title,
27
+ canonicalUrl: post.canonicalUrl,
28
+ socialProfiles: site.sharing.socialProfiles
29
+ })
30
+ : [],
31
+ postTableOfContents: ({ post }) => post?.publicationState === 'published'
32
+ ? renderedDocument(post).tableOfContents
33
+ : [],
22
34
  seo: ({ post, site }) => post?.publicationState === 'published'
23
- ? postSeo({ post, site, renderedHtml: markdownLibrary.render(post.body) })
35
+ ? postSeo({ post, site, renderedHtml: renderedDocument(post).html })
24
36
  : null
25
37
  }
26
38
  };
@@ -30,6 +42,17 @@ export default class ValidatedPostPages {
30
42
  if (post.publicationState === 'tombstoned') {
31
43
  return `<p>POST deleted on ${post.frontmatter.deleteDate}</p>`;
32
44
  }
33
- return markdownLibrary.render(post.body);
45
+ return renderedDocument(post).html;
34
46
  }
35
47
  }
48
+
49
+ const renderedDocuments = new WeakMap();
50
+
51
+ function renderedDocument(post) {
52
+ let document = renderedDocuments.get(post);
53
+ if (!document) {
54
+ document = renderMarkdownDocument(post.body);
55
+ renderedDocuments.set(post, document);
56
+ }
57
+ return document;
58
+ }