From 4dfcb9ab5396a39f9a90152ce6a22d538e4c8658 Mon Sep 17 00:00:00 2001
From: ayushnirwal <53055971+ayushnirwal@users.noreply.github.com>
Date: Mon, 12 May 2025 16:42:50 +0530
Subject: [PATCH 1/3] chore: add usage docs for seo
Signed-off-by: ayushnirwal <53055971+ayushnirwal@users.noreply.github.com>
---
docs/seo.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 docs/seo.md
diff --git a/docs/seo.md b/docs/seo.md
new file mode 100644
index 00000000..0f86b64d
--- /dev/null
+++ b/docs/seo.md
@@ -0,0 +1,55 @@
+# SEO Metadata
+
+SnapWP export 2 main functions `getPageMetadata` and `getLayoutMetadata` to add meta tags for SEO.
+`getLayoutMetadata` - Gets SEO data for the site.
+`getPageMetadata` - Gets SEO data related to the template. Adds update icon
+
+## Registering a new plugin
+The SEO functionality can be extended by registering new plugins. Below is an example of updated root layout.
+
+```typescript
+import { RootLayout } from '@snapwp/next';
+import { getLayoutMetadata, Seo } from '@snapwp/next/seo';
+import type { Metadata } from 'next';
+import type { PropsWithChildren } from 'react';
+
+// Register a plugin before calling function `getLayoutMetadata`
+Seo.registerPlugin(
+ {
+ fragment: PluginFragmentDoc,
+ parseMetadata: parserFunction,
+ location:'page'
+ }
+);
+
+export default function Layout( { children }: PropsWithChildren ) {
+ return (
+
+ <>{ children }>
+
+ );
+}
+
+/**
+ * Generate site meta data.
+ * @return Metadata for SEO.
+ */
+export async function generateMetadata(): Promise< Metadata > {
+ const metadata = await getLayoutMetadata();
+
+ return {
+ ...metadata,
+ };
+}
+```
+
+
+## Anatomy of a SEO plugin
+
+An plugin requires 3 things to be registered.
+
+**Fragment** to define the data needed from the WP server.
+**Parser** to parse the fragment data to be consumable by NextJS.
+**Location** has value of either `page` or `layout`. This defines if the parsed meta data should be added to the returned value of `getPageMetadata` or `getLayoutMetadata`.
+
+Note: if a plugin is defined to have the location `page` the fragment should be on `RootQuery` and for `layout` it should be a fragment of `RenderedTemplate`.
\ No newline at end of file
From 94b8d4710a18a019c99dd57bbea5428d77df9591 Mon Sep 17 00:00:00 2001
From: ayushnirwal <53055971+ayushnirwal@users.noreply.github.com>
Date: Mon, 12 May 2025 16:44:27 +0530
Subject: [PATCH 2/3] chore: format
Signed-off-by: ayushnirwal <53055971+ayushnirwal@users.noreply.github.com>
---
docs/seo.md | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/docs/seo.md b/docs/seo.md
index 0f86b64d..618654b3 100644
--- a/docs/seo.md
+++ b/docs/seo.md
@@ -1,10 +1,11 @@
# SEO Metadata
SnapWP export 2 main functions `getPageMetadata` and `getLayoutMetadata` to add meta tags for SEO.
-`getLayoutMetadata` - Gets SEO data for the site.
-`getPageMetadata` - Gets SEO data related to the template. Adds update icon
+`getLayoutMetadata` - Gets SEO data for the site.
+`getPageMetadata` - Gets SEO data related to the template. Adds update icon
## Registering a new plugin
+
The SEO functionality can be extended by registering new plugins. Below is an example of updated root layout.
```typescript
@@ -43,13 +44,12 @@ export async function generateMetadata(): Promise< Metadata > {
}
```
-
## Anatomy of a SEO plugin
-An plugin requires 3 things to be registered.
+An plugin requires 3 things to be registered.
-**Fragment** to define the data needed from the WP server.
+**Fragment** to define the data needed from the WP server.
**Parser** to parse the fragment data to be consumable by NextJS.
**Location** has value of either `page` or `layout`. This defines if the parsed meta data should be added to the returned value of `getPageMetadata` or `getLayoutMetadata`.
-Note: if a plugin is defined to have the location `page` the fragment should be on `RootQuery` and for `layout` it should be a fragment of `RenderedTemplate`.
\ No newline at end of file
+Note: if a plugin is defined to have the location `page` the fragment should be on `RootQuery` and for `layout` it should be a fragment of `RenderedTemplate`.
From 8d60bc449b3b164264fbc09fb79c8a737a6f81fc Mon Sep 17 00:00:00 2001
From: Dovid Levine
Date: Tue, 13 May 2025 14:07:46 +0300
Subject: [PATCH 3/3] chore: format
---
docs/seo.md | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/docs/seo.md b/docs/seo.md
index 618654b3..54867855 100644
--- a/docs/seo.md
+++ b/docs/seo.md
@@ -1,8 +1,9 @@
# SEO Metadata
-SnapWP export 2 main functions `getPageMetadata` and `getLayoutMetadata` to add meta tags for SEO.
-`getLayoutMetadata` - Gets SEO data for the site.
-`getPageMetadata` - Gets SEO data related to the template. Adds update icon
+SnapWP exports two main functions to add meta tags for SEO:
+
+- `getLayoutMetadata`: Gets SEO data for the site.
+- `getPageMetadata`: Gets SEO data related to the template. Adds update icon
## Registering a new plugin
@@ -16,10 +17,10 @@ import type { PropsWithChildren } from 'react';
// Register a plugin before calling function `getLayoutMetadata`
Seo.registerPlugin(
- {
+ {
fragment: PluginFragmentDoc,
parseMetadata: parserFunction,
- location:'page'
+ location:'page'
}
);
@@ -48,8 +49,9 @@ export async function generateMetadata(): Promise< Metadata > {
An plugin requires 3 things to be registered.
-**Fragment** to define the data needed from the WP server.
-**Parser** to parse the fragment data to be consumable by NextJS.
-**Location** has value of either `page` or `layout`. This defines if the parsed meta data should be added to the returned value of `getPageMetadata` or `getLayoutMetadata`.
+- **Fragment** to define the data needed from the WP server.
+- **Parser** to parse the fragment data to be consumable by NextJS.
+- **Location** has value of either `page` or `layout`. This defines if the parsed meta data should be added to the returned value of `getPageMetadata` or `getLayoutMetadata`.
-Note: if a plugin is defined to have the location `page` the fragment should be on `RootQuery` and for `layout` it should be a fragment of `RenderedTemplate`.
+> [!Note]
+> If a plugin is defined to have the location `page` the fragment should be on `RootQuery` and for `layout` it should be a fragment of `RenderedTemplate`.