0.1.29 • Published 3 years ago
next-wordpress v0.1.29
next-wordpress
create ssg pages using next.js and wordpress. This packages has no extra dependancies when using with next.js.
Getting Started
- yarn add next-wordpress
How
make sure to set the env vars BLOG_DOMAIN
for middleware rewrites and BLOG_URL
for the wordpress source.
BLOG_URL=https://a11ywatch.wpcomstaging.com
BLOG_DOMAIN=a11ywatch.blog
create a new folder in your pages directory called blog
with a file called [...slug].tsx
or [...slug].jsx
and add the following below.
import type { GetStaticProps } from "next";
import React from "react";
import { WordPressPage, getBlogPage, BlogPageProps } from "next-wordpress";
function Blogs(props: BlogPageProps) {
return <WordPressPage {...props} />;
}
export async function getStaticPaths() {
return { paths: [], fallback: "blocking" };
}
export const getStaticProps: GetStaticProps = async (context) => {
const { slug } = context.params ?? {};
const websiteUrl = Array.isArray(slug) ? slug : [];
let props = {};
try {
props = await getBlogPage(websiteUrl.join("/"));
} catch (e) {
console.error(e);
}
return {
props,
revalidate: 60 * 12 * 2,
};
};
export default Blogs;
optional:
pages/blog/__middleware.ts
export { middleware } from "next-wordpress";
0.1.29
3 years ago
0.1.28
3 years ago
0.1.27
3 years ago
0.1.26
3 years ago
0.1.25
3 years ago
0.1.23
3 years ago
0.1.22
3 years ago
0.1.20
3 years ago
0.1.19
3 years ago
0.1.18
3 years ago
0.1.17
3 years ago
0.1.16
3 years ago
0.1.15
4 years ago
0.1.14
4 years ago
0.1.13
4 years ago
0.1.12
4 years ago
0.1.11
4 years ago
0.1.10
4 years ago
0.1.9
4 years ago
0.1.8
4 years ago
0.1.7
4 years ago
0.1.6
4 years ago
0.1.4
4 years ago
0.1.3
4 years ago
0.1.2
4 years ago
0.1.1
4 years ago