@farming-labs/next 0.0.10 → 0.0.12
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.
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* Runs between remark-frontmatter and remark-mdx-frontmatter.
|
|
6
6
|
* Reads title/description from the YAML node and appends openGraph + twitter
|
|
7
7
|
* fields so that remark-mdx-frontmatter exports them as part of `metadata`.
|
|
8
|
+
*
|
|
9
|
+
* Skips injection when frontmatter already has `openGraph:` or `ogImage:`, so
|
|
10
|
+
* pages can use static OG images from frontmatter instead of the dynamic endpoint.
|
|
8
11
|
*/
|
|
9
12
|
interface RemarkOgOptions {
|
|
10
13
|
endpoint?: string;
|
|
@@ -4,11 +4,16 @@ function extractField(yaml, key) {
|
|
|
4
4
|
const m = yaml.match(re);
|
|
5
5
|
return m?.[1] ?? m?.[2] ?? m?.[3];
|
|
6
6
|
}
|
|
7
|
+
/** True if the YAML already defines openGraph or ogImage (static OG). */
|
|
8
|
+
function hasStaticOg(yaml) {
|
|
9
|
+
return /^\s*openGraph\s*:/m.test(yaml) || /^\s*ogImage\s*:/m.test(yaml);
|
|
10
|
+
}
|
|
7
11
|
function remarkOg(options = {}) {
|
|
8
12
|
const { endpoint = "/api/og" } = options;
|
|
9
13
|
return (tree) => {
|
|
10
14
|
const yamlNode = tree.children.find((n) => n.type === "yaml");
|
|
11
15
|
if (!yamlNode) return;
|
|
16
|
+
if (hasStaticOg(yamlNode.value)) return;
|
|
12
17
|
const title = extractField(yamlNode.value, "title");
|
|
13
18
|
if (!title) return;
|
|
14
19
|
const description = extractField(yamlNode.value, "description");
|