imranhsayed / nextjs-headless-wordpress Goto Github PK
View Code? Open in Web Editor NEW🔥 Nextjs Headless WordPress
Home Page: https://codeytek.com/course/next-js-headless-wordpress-course/
License: GNU General Public License v3.0
🔥 Nextjs Headless WordPress
Home Page: https://codeytek.com/course/next-js-headless-wordpress-course/
License: GNU General Public License v3.0
Setup Eslint using WordPress eslint config.
Hello, I've been using this as a small boilerplate to build a website and I have noticed that some of the default settings on the Gutenberg stylesheets imported into the project from node-wordpress seem to override TailwindCSS classes used within the Gutenberg editor. Especially the top margin values. Do you have any recommended solution for prioritizing TailwindCSS over these styles?
The following plugin needs to be explored to add translation
https://github.com/valu-digital/wp-graphql-polylang
This is one of the issues when you go Headless with WordPress it got plugins like SNAP AutoPoster, that automatically post your new blog post to social media, which is great for marketing. But with Headless WordPress it would post a URL to the admin panel, so the plugins become useless, is there a way to set up some kind of automatic system to post social media updates for Next.js?
Another issue maybe is that those automatic posts need some kind of delay like the blog post may not exist yet on the Next.js site, so FB and Twitter wouldn't be able to get the meta preview data?
You can just ignore this, just listing some things I run into with going Headless WP!
I can't find any good info about deploying a Headless WP via Docker on DigitalOcean or anywhere else. Perhaps this is considered an easy task because we're using Docker (Docker newbie here)?
Just a few bullet points on how to deploy this amazing project so we can see our project in production would be greatly appreciated 🙏
Upgrade to next.js v10
Is your feature request related to a problem? Please describe.
During compose up Docker i got issue related with processor M1
When Docker working with mysql container i got an error:
ERROR: no matching manifest for linux/arm64/v8 in the manifest list entries
Describe the solution you'd like
In Readme should create section about ARM M1 issue or information about that
Describe alternatives you've considered
I changed the image in the file docker-compose.yml, that resolve my issue with M1.
image: mysql:8.0 -> image: mysql/mysql-server:8.0.23
Additional context
How i can help develop repo with that type issue ? Should create PR with expand readme or update file docker-compose.yml ?
Currently we need to use --allow-root
to run wp
command
We need to make default php user as www-data
Add readme about this behaviour under title #Project Structure
One of the things we lose while going HeadLess with WordPress is the RSS feed that is used by some 3rd party sites to get your blogs post to list. And also to pull the content of your site in a newsletter solution like MailChimp and so on.
It would be awesome if the RSS feed also included the feature image.
I found this tutorial to create with Next.js but maybe we can do better, also wonder who to auto rebuild the RSS feed whenever a new blog post is added, like Next.js not seems to have the same hooks as Gatsby.js
Sample code: https://dev.to/kendalmintcode/create-a-next-js-rss-feed-for-your-static-website-210p
Currently only backend is dockerized.
Docker has some limitations on port for mac and Windows however, if we can come up with some idea, dockerizing front-end would be better as well
We have already done some work in this branch.
Trying to fetch data from slug [...slug].js page but showing undefined.
slug page code here
import {GET_PAGES_URI} from '../queries/pages/get-pages';
import {isEmpty} from 'lodash';
import {GET_PAGE} from '../queries/pages/get-page';
import {useRouter} from 'next/router';
import client from '../apollo/client';
import Layout from '../components/layout';
const Page = ( {data} ) => {
console.log('data', data);
const router = useRouter();
// If the page is not yet generated, this will be displayed
// initially until getStaticProps() finishes running
if ( router.isFallback ) {
return <div>Loading...</div>;
}
return (
<>
<Layout data={data}>
{router?.query?.slug.join("/")}
</Layout>
</>
);
}
export default Page;
export async function getStaticProps( {params} ) {
const {data, loading, networkStatus} = await client.query( {
query: GET_PAGE,
variables: {
uri: params?.slug.join( '/' ),
},
} );
return {
props: {
data: {
menus: {
headerMenus: data?.headerMenus?.edges || [],
footerMenus: data?.footerMenus?.edges || [],
},
page: data?.page ?? {},
path: params?.slug.join("/"),
}
},
revalidate: 1,
};
}
export async function getStaticPaths() {
const {data} = await client.query( {
query: GET_PAGES_URI
});
const pathsData = [];
data?.pages?.nodes && data?.pages?.nodes.map( page => {
if ( ! isEmpty( page?.uri ) ) {
const slugs = page?.uri?.split( '/' ).filter( pageSlug => pageSlug );
pathsData.push( {params: {slug: slugs}} );
}
} );
return {
paths: pathsData,
fallback: true
};
}
This package need to be explored and sitemap needs to be generated.
https://www.npmjs.com/package/nextjs-sitemap-generator
Add loadmore feature on blog page
Add a diagram( image) in README showing the setup of backend and frontend and the flow of request from backend to frontend.
Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function "graphql_activation_callback" not found or invalid function name in /var/www/html/wp-includes/class-wp-hook.php:310 Stack trace: #0 /var/www/html/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters('', Array) #1 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #2 /var/www/html/wp-admin/plugins.php(194): do_action('activate_wp-gra...') #3 {main} thrown in /var/www/html/wp-includes/class-wp-hook.php on line 310
Hello Imranhsayed, thank you for the repo and lessons.
The fields have the following values:
metaRobotsNoindex, // index | noindex
metaRobotsNofollow, // follow | nofollow
So in the component, it should be
noindex={metaRobotsNoindex === "noindex"}
nofollow={metaRobotsNofollow === "nofollow"}
Packages should be installed by yarn
I am following your tutorial and trying to build a site with NextJS and Wordpress as backend. I have my Wordpress site setup else where, so I am using only your frontend folder, copied contents of this folder to my local project directory and changed settings to meet my needs.
When I try yarn dev, I get 500 status code from ApolloClient, following is what I see in VS Code terminal.
https://circlej.smr-sandbox.com/graphql
ApolloError: Response not successful: Received status code 500
at new ApolloError (C:\Babu\Learning\NextJs\CircleJ2\node_modules@apollo\client\errors\errors.cjs.js:31:28)
at C:\Babu\Learning\NextJs\CircleJ2\node_modules@apollo\client\core\core.cjs.js:1457:19
at C:\Babu\Learning\NextJs\CircleJ2\node_modules@apollo\client\utilities\utilities.cjs.js:936:69
at new Promise ()
at Object.error (C:\Babu\Learning\NextJs\CircleJ2\node_modules@apollo\client\utilities\utilities.cjs.js:936:21)
at notifySubscription (C:\Babu\Learning\NextJs\CircleJ2\node_modules\zen-observable\lib\Observable.js:140:18)
at onNotify (C:\Babu\Learning\NextJs\CircleJ2\node_modules\zen-observable\lib\Observable.js:179:3)
at SubscriptionObserver.error (C:\Babu\Learning\NextJs\CircleJ2\node_modules\zen-observable\lib\Observable.js:240:7)
at C:\Babu\Learning\NextJs\CircleJ2\node_modules@apollo\client\utilities\utilities.cjs.js:924:68
at Array.forEach () {
graphQLErrors: [],
networkError: Error [ServerError]: Response not successful: Received status code 500
at Object.throwServerError (C:\Babu\Learning\NextJs\CircleJ2\node_modules@apollo\client\link\utils\utils.cjs.js:45:17)
at C:\Babu\Learning\NextJs\CircleJ2\node_modules@apollo\client\link\http\http.cjs.js:31:19
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:93:5) {
response: Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: [Object],
[Symbol(Response internals)]: [Object]
},
statusCode: 500,
result: {
code: 'internal_server_error',
message: '
There has been a critical error on this website.
Learn more about debugging in WordPress.
',There has been a critical error on this website.
Learn more about debugging in WordPress.
',Then on a hunch I went ahead and typed https://circlej.smr-sandbox.com/graphql endpoint in the browser get an error, looks like wp-graphql-gutenberg-0.3.7 is having problems, have you seen this error?
Fatal error: Uncaught WPGraphQLGutenberg\Blocks\RegistryNotSourcedException: Client side block registry is missing. You need to open up gutenberg or load it from WPGraphQLGutenberg Admin page. in /home/customer/www/circlej.smr-sandbox.com/public_html/wp-content/plugins/wp-graphql-gutenberg-0.3.7/src/Blocks/Registry.php:41 Stack trace: #0 /home/customer/www/circlej.smr-sandbox.com/public_html/wp-content/plugins/wp-graphql-gutenberg-0.3.7/src/Schema/Types/BlockTypes.php(253): WPGraphQLGutenberg\Blocks\Registry::get_registry() #1 /home/customer/www/circlej.smr-sandbox.com/public_html/wp-includes/class-wp-hook.php(287): WPGraphQLGutenberg\Schema\Types\BlockTypes->WPGraphQLGutenberg\Schema\Types{closure}(Object(WPGraphQL\Registry\TypeRegistry)) #2 /home/customer/www/circlej.smr-sandbox.com/public_html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array) #3 /home/customer/www/circlej.smr-sandbox.com/public_html/wp-includes/plugin.php(484): WP_Hook->do_action(Array) #4 /home/customer/www/circlej.smr-sandbox.c in /home/customer/www/circlej.smr-sandbox.com/public_html/wp-content/plugins/wp-graphql-gutenberg-0.3.7/src/Blocks/Registry.php on line 41
Thanks for any help.
This is my header component --
`
import { isEmpty } from "lodash";
import Nav from "./Nav";
const Header = ({ headerMenus }) => {
// console.log(headerMenus); <- Here i get the menus
if (isEmpty(headerMenus)) {
return null;
}
return (
//<Header> // <Nav headerMenus = {headerMenus}/> // </Header>
);
};
export default Header;
`
when I send data through props to nav I am not getting any data in nav component please help here the code of Nav
`
const Nav = ({headerMenus}) =>{
// console.log(headerMenus); <~~ Not getting data here so i can't return anything through this
return;
};
export default Nav;
`
Add information about this in README.
Here's my docker-compose.yml file:
`version: '3.9'
services:
composer:
image: composer
command: update
volumes:
- ./wordpress:/app
mysql:
image: mysql:8.0
volumes:
- mysql_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
volumes:
- ./mysql:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
depends_on:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
ports:
- 8183:80
wordpress:
depends_on:
- mysql
- composer
image: wordpress:latest
ports:
- "8020:80"
restart: always
environment:
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
- ./wordpress:/var/www/html
volumes:
mysql_data: {} `
If I run docker-compose -f backend/docker-compose.yml up I get this:
ERROR: Version in "./backend/docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the services
key, or omit the version
key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
My docker compse ver is::
Docker version 18.09.7, build 2d0083d
User runs some commmand
Its asks about
Hi, I've followed your great YouTube tutorials, and everything worked until video “7: getStaticProps Nextjs” where I get this error:
Server Error
GraphQLError: Syntax Error: Unexpected Name "headerMenus".
This error happened while generating the page. Any console logs will be displayed in the terminal window.
The issue is on on line 4 in get-menus.js
(export const GET_MENUS = gql
)
Here's my entire get-menus.js
file:
import { gql } from "@apollo/client";
import MenuFragment from "./fragments/menus";
export const GET_MENUS = gql`
headerMenus: menuItems(where: {location: HCMS_MENU_HEADER, parentId: "0"}) {
edges {
node {
...MenuFragment
childItems {
edges {
node {
...MenuFragment
}
}
}
}
}
}
footerMenus: menuItems(where: {location: HCMS_MENU_FOOTER, parentId: "0"}) {
edges {
node {
...MenuFragment
}
}
${MenuFragment}
`;
There are a couple of people in the comments section on that video that have the same problem.
What am I doing wrong?
Is there a complete index with links for all videos in this course? I have only found partial indexes so far. It would really help if the README had a list of all the videos in the course together with links to the videos and to the documents referenced in each video.
Hi @imranhsayed ,
I created a Next JS project with wpgraqhl. I follow all your tutorials steps. I have faced one issues here details are given below -
Current the docker file does not have the option for wp-cli, so we need to add that.
Add phpmyadmin
Yoast plugin does not get activated after installing it via composer.
Current docker file pull composer with PHP version 8 which conflicting with Wordpress SEO plugin.
Setup Stylelint
If anyone else getting this error:
'NODE_OPTIONS' is not recognized as an internal or external command, bla bla
Here is the solution:
1. Install the cross-env package ('npm i cross-env' or 'yarn add cross-env')
2. Replace the dev script in the package.json file with:
"dev": "cross-env NODE_OPTIONS='--inspect' next",
setup phpcs
Questions from YouTube:
1.how to migrate to docker wordpress.
2.how to backup database and file WordPress in docker.
3.how to secure docker wordpress.
4.how to multiple using docker..
Add Headless CMS plugin via composer
I tried building this project today but npm install fails with a dependency issue:
Could not resolve dependency:
peer react@"^0.14 || ^15.0.0 || ^16.0.0-alpha" from [email protected]
node_modules/react-outside-click-handler/node_modules/airbnb-prop-types
This appears to be due to this airbnb issue:
Any thoughts on the best way to resolve this. Can you update the dependencies to reflect this
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.