-
Notifications
You must be signed in to change notification settings - Fork 2
docs(example): Nuxt Data Fetch #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexwpengine
wants to merge
6
commits into
main
Choose a base branch
from
example-nuxt-data-fetch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alexwpengine marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"phpVersion": "8.3", | ||
"plugins": [ | ||
"https://github.com/wp-graphql/wp-graphql/releases/latest/download/wp-graphql.zip", | ||
"https://downloads.wordpress.org/plugin/classic-editor.latest-stable.zip", | ||
"https://downloads.wordpress.org/plugin/wpgraphql-ide.latest-stable.zip" | ||
], | ||
"themes": [ | ||
"https://downloads.wordpress.org/theme/twentytwentyone.latest-stable.zip" | ||
], | ||
"env": { | ||
"development": { | ||
"port": 8890, | ||
"mysqlPort": 55090 | ||
}, | ||
"tests": { | ||
"port": 8891, | ||
"mysqlPort": 55091 | ||
} | ||
}, | ||
"config": { | ||
"WP_DEBUG": true, | ||
"SCRIPT_DEBUG": false, | ||
"GRAPHQL_DEBUG": true, | ||
"WP_DEBUG_LOG": true, | ||
"WP_DEBUG_DISPLAY": false, | ||
"SAVEQUERIES": false | ||
}, | ||
"mappings": { | ||
"db": "./wp-env/db", | ||
"wp-content/uploads": "./wp-env/uploads", | ||
".htaccess": "./wp-env/setup/.htaccess" | ||
}, | ||
"lifecycleScripts": { | ||
"afterStart": "wp-env run cli -- wp theme activate twentytwentyone && wp-env run cli -- wp theme delete --all && wp-env run cli -- wp plugin delete hello-dolly && wp-env run cli -- wp rewrite structure '/%postname%/' && wp-env run cli -- wp rewrite flush" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Nuxt Data fetching | ||
|
||
In this example we show how to implement the WP Template Hierarchy in Nuxt for use with a Headless WordPress backend using WPGraphQL. | ||
|
||
## Getting Started | ||
|
||
> [!IMPORTANT] | ||
> Docker Desktop needs to be installed to run WordPress locally. | ||
|
||
1. Run `npm run example:setup` to install dependencies and configure the local WP server. | ||
2. Run `npm run example:start` to start the WP server and Nuxt development server. | ||
|
||
> [!NOTE] | ||
> When you kill the long running process this will not shutdown the local WP instance, only Nuxt. You must run `npm run example:stop` to kill the local WP server. | ||
|
||
## Trouble Shooting | ||
|
||
To reset the WP server and re-run setup you can run `npm run example:prune` and confirm "Yes" at any prompts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Nuxt dev/build outputs | ||
.output | ||
.data | ||
.nuxt | ||
.nitro | ||
.cache | ||
dist | ||
|
||
# Node dependencies | ||
node_modules | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
||
# Misc | ||
.DS_Store | ||
.fleet | ||
.idea | ||
|
||
# Local env files | ||
.env | ||
.env.* | ||
!.env.example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Nuxt Minimal Starter | ||
|
||
Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more. | ||
|
||
## Setup | ||
|
||
Make sure to install dependencies: | ||
|
||
```bash | ||
# npm | ||
npm install | ||
|
||
# pnpm | ||
pnpm install | ||
|
||
# yarn | ||
yarn install | ||
|
||
# bun | ||
bun install | ||
``` | ||
|
||
## Development Server | ||
|
||
Start the development server on `http://localhost:3000`: | ||
|
||
```bash | ||
# npm | ||
npm run dev | ||
|
||
# pnpm | ||
pnpm dev | ||
|
||
# yarn | ||
yarn dev | ||
|
||
# bun | ||
bun run dev | ||
``` | ||
|
||
## Production | ||
|
||
Build the application for production: | ||
|
||
```bash | ||
# npm | ||
npm run build | ||
|
||
# pnpm | ||
pnpm build | ||
|
||
# yarn | ||
yarn build | ||
|
||
# bun | ||
bun run build | ||
``` | ||
|
||
Locally preview production build: | ||
|
||
```bash | ||
# npm | ||
npm run preview | ||
|
||
# pnpm | ||
pnpm preview | ||
|
||
# yarn | ||
yarn preview | ||
|
||
# bun | ||
bun run preview | ||
``` | ||
|
||
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<script setup> | ||
import { onMounted } from 'vue'; | ||
import { initializePostsPerPageCache } from './lib/utils'; | ||
import Header from './components/Header.vue'; | ||
import Footer from './components/Footer.vue'; | ||
|
||
// // Initialize on both client and server | ||
// initializePostsPerPageCache().catch(err => { | ||
// console.error('Error initializing cache in app.vue:', err); | ||
// }); | ||
|
||
// // Also try on mount just to be sure | ||
// onMounted(() => { | ||
// initializePostsPerPageCache().catch(err => { | ||
// console.error('Error initializing cache on mount:', err); | ||
// }); | ||
// }); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<Header /> | ||
<main class="container mx-auto px-4"> | ||
<NuxtPage /> | ||
</main> | ||
<Footer /> | ||
</div> | ||
</template> |
24 changes: 24 additions & 0 deletions
24
examples/nuxt/data-fetch/example-app/assets/scss/_variables.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Colors | ||
$primary-color: #0066cc; | ||
$secondary-color: #ff6600; | ||
$text-color: #333333; | ||
$light-bg: #f8f8f8; | ||
$border-color: #eeeeee; | ||
$gutter: 1rem; | ||
// Spacing | ||
$spacing-unit: 8px; | ||
$spacing-small: $spacing-unit; | ||
$spacing-medium: $spacing-unit * 2; | ||
$spacing-large: $spacing-unit * 3; | ||
$spacing-xlarge: $spacing-unit * 4; | ||
|
||
// Breakpoints | ||
$breakpoint-small: 576px; | ||
$breakpoint-medium: 768px; | ||
$breakpoint-large: 992px; | ||
$breakpoint-xlarge: 1200px; | ||
|
||
// Typography | ||
$font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; | ||
$font-size-base: 16px; | ||
$line-height-base: 1.6; |
14 changes: 14 additions & 0 deletions
14
examples/nuxt/data-fetch/example-app/assets/scss/components/button.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@use "../variables" as *; | ||
|
||
.button { | ||
padding: .5rem $gutter * 1.5; | ||
color: white; | ||
&.button-primary { | ||
background-color: $primary-color; | ||
} | ||
&.button-link { | ||
background-color: transparent; | ||
color: $primary-color; | ||
border: 1px solid $primary-color; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
examples/nuxt/data-fetch/example-app/assets/scss/components/post-card.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
@use "../variables" as *; | ||
.post-card { | ||
overflow: auto; | ||
margin-bottom: $gutter * 2; | ||
.post-card-content { | ||
border: 1px solid #ddd; | ||
padding: $gutter; | ||
} | ||
header { | ||
margin-bottom: 1rem; | ||
} | ||
.post-meta { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin-bottom: 0.5rem; | ||
.author { | ||
font-weight: bold; | ||
color: #333; | ||
display: flex; | ||
align-items: center; | ||
.author-name { | ||
color: $primary-color; | ||
text-decoration: none; | ||
font-size: 0.75rem; | ||
&:hover { | ||
text-decoration: underline; | ||
} | ||
} | ||
.author-avatar { | ||
width: 1.5rem; | ||
height: 1.5rem; | ||
border-radius: 50%; | ||
margin-right: 0.5rem; | ||
vertical-align: middle; | ||
} | ||
} | ||
time { | ||
color: #666; | ||
font-size: 0.65rem; | ||
} | ||
} | ||
.categories-container { | ||
display: flex; | ||
flex-wrap: wrap; | ||
font-size: 0.75rem; | ||
gap: 0.5rem; | ||
margin-bottom: 0.5rem; | ||
|
||
.category { | ||
background-color: #f0f0f0; | ||
padding: 0.25rem 0.5rem; | ||
border-radius: 4px; | ||
font-size: 0.75rem; | ||
color: #555; | ||
text-decoration: none; | ||
&:hover { | ||
background-color: #e0e0e0; | ||
} | ||
} | ||
} | ||
.featured-image-container { | ||
|
||
img { | ||
max-width: 100%; | ||
height: auto; | ||
} | ||
} | ||
|
||
.post-title { | ||
font-size: 1.25rem; | ||
font-weight: bold; | ||
margin-bottom: 0.5rem; | ||
overflow-wrap: break-word; | ||
word-wrap: break-word; | ||
-webkit-hyphens: auto; | ||
hyphens: auto; | ||
} | ||
|
||
.post-excerpt { | ||
font-size: 0.875rem; | ||
color: #333; | ||
margin-bottom: 1rem; | ||
|
||
overflow-wrap: break-word; | ||
word-wrap: break-word; | ||
-webkit-hyphens: auto; | ||
hyphens: auto; | ||
|
||
} | ||
.read-more { | ||
display: flex; | ||
margin-top: $gutter; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@use 'reset'; | ||
@use 'layout'; | ||
@use 'helpers'; | ||
@use './components/button'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.