Implement internationalization in pages and update CMS clients

The commit mainly revamps the code to support internationalization in various pages like pricing, docs, blog, etc. It modifies the code to generate metadata asynchronously, accommodating internationalized page titles and subtitles. Also, the commit restructures CMS Client scripts, particularly for ContentLayer and Wordpress. For Wordpress, it updates API fetch routes and handles embedded children data. Furthermore, unnecessary logging statements are cleaned up, and minor updates are done for better UI and code efficiency.
This commit is contained in:
giancarlo
2024-04-03 16:05:34 +08:00
parent 12058274f5
commit 048d58dcdf
28 changed files with 227 additions and 157 deletions

View File

@@ -5,7 +5,7 @@ Implementation of the CMS layer using the [Wordpress](https://wordpress.org) lib
This implementation is used when the host app's environment variable is set as:
```
CMS_TYPE=wordpress
CMS_CLIENT=wordpress
```
Additionally, please set the following environment variables:
@@ -26,4 +26,19 @@ or
npm run dev
```
from this package's root directory.
from this package's root directory.
The credentials for the Wordpress instance are:
```
WORDPRESS_DB_HOST=db
WORDPRESS_DB_USER=wordpress
WORDPRESS_DB_PASSWORD=wordpress
WORDPRESS_DB_NAME=wordpress
```
You will be asked to set up the Wordpress instance when you visit `http://localhost:8080` for the first time.
## Note for Wordpress REST API
To make the REST API in your Wordpress instance work, please change the permalink structure to `/%post%/` from the Wordpress admin panel.

View File

@@ -19,7 +19,7 @@ services:
wordpress:
image: wordpress:latest
ports:
- 80:80
- 8080:80
restart: always
environment:
- WORDPRESS_DB_HOST=db

View File

@@ -0,0 +1,3 @@
export function WordpressContentRenderer(props: { content: string }) {
return <div dangerouslySetInnerHTML={{ __html: props.content }} />;
}

View File

@@ -70,7 +70,7 @@ export class WordpressClient implements CmsClient {
let children: Cms.ContentItem[] = [];
const embeddedChildren = (
item._embedded ? item._embedded['wp:children'] : []
item._embedded ? item._embedded['wp:children'] ?? [] : []
) as WP_REST_API_Post[];
if (options?.depth && options.depth > 0) {
@@ -128,8 +128,8 @@ export class WordpressClient implements CmsClient {
);
}
async getContentItemById(slug: string) {
const url = `${this.apiUrl}/wp-json/wp/v2/posts?slug=${slug}`;
async getContentItemById(slug: string, type: 'posts' | 'pages' = 'posts') {
const url = `${this.apiUrl}/wp-json/wp/v2/${type}?slug=${slug}&_embed`;
const response = await fetch(url);
const data = (await response.json()) as WP_REST_API_Post[];
const item = data[0];