Skip to content

Commit 867b7ef

Browse files
authored
Merge pull request #369 from wpengine/astro-previews-real
docs: initial astro previews example
2 parents f2c183d + 51de63e commit 867b7ef

29 files changed

+1878
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"phpVersion": "8.3",
3+
"plugins": [
4+
"https://github.com/wp-graphql/wp-graphql/releases/latest/download/wp-graphql.zip",
5+
"https://github.com/wpengine/hwptoolkit/releases/download/%40wpengine%2Fhwp-previews-wordpress-plugin-0.0.8/hwp-previews.zip",
6+
"https://github.com/wp-graphql/wpgraphql-ide/releases/latest/download/wpgraphql-ide.zip"
7+
],
8+
"themes": ["https://downloads.wordpress.org/theme/nude.1.2.zip"],
9+
"config": {
10+
"WP_DEBUG": true,
11+
"SCRIPT_DEBUG": false,
12+
"GRAPHQL_DEBUG": true,
13+
"WP_DEBUG_LOG": true,
14+
"WP_DEBUG_DISPLAY": false,
15+
"SAVEQUERIES": false
16+
},
17+
"mappings": {
18+
"db": "./wp-env/db",
19+
"wp-content/uploads": "./wp-env/uploads",
20+
".htaccess": "./wp-env/setup/.htaccess"
21+
},
22+
"lifecycleScripts": {
23+
"afterStart": "wp-env run cli -- wp theme activate nude && wp-env run cli -- wp theme delete --all && wp-env run cli -- wp rewrite structure '/%postname%/' && wp-env run cli -- wp rewrite flush"
24+
}
25+
}

examples/astro/previews/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Astro Template HIerarchy and Data fetching w/URQL Example
2+
3+
In this example we show how to implement the WP Template Hierarchy in Astro for use with a Headless WordPress backend using WPGraphQL. We use URQL for all routing and fetching page content.
4+
5+
## Getting Started
6+
7+
> [!IMPORTANT]
8+
> Docker Desktop needs to be installed to run WordPress locally.
9+
10+
1. Run `npm run example:setup` to install dependencies and configure the local WP server.
11+
2. Run `npm run example:start` to start the WP server and Astro development server.
12+
13+
> [!NOTE]
14+
> When you kill the long running process this will not shutdown the local WP instance, only Astro. You must run `npm run example:stop` to kill the local WP server.
15+
16+
## Trouble Shooting
17+
18+
To reset the WP server and re-run setup you can run `npm run example:prune` and confirm "Yes" at any prompts.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# build output
2+
dist/
3+
4+
# generated types
5+
.astro/
6+
7+
# dependencies
8+
node_modules/
9+
10+
# logs
11+
npm-debug.log*
12+
yarn-debug.log*
13+
yarn-error.log*
14+
pnpm-debug.log*
15+
16+
# environment variables
17+
.env
18+
.env.production
19+
20+
# macOS-specific files
21+
.DS_Store
22+
23+
# jetbrains setting folder
24+
.idea/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Astro Starter Kit: Basics
2+
3+
```sh
4+
npm create astro@latest -- --template basics
5+
```
6+
7+
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/basics)
8+
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/basics)
9+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/basics/devcontainer.json)
10+
11+
> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!
12+
13+
![just-the-basics](https://github.com/withastro/astro/assets/2244813/a0a5533c-a856-4198-8470-2d67b1d7c554)
14+
15+
## 🚀 Project Structure
16+
17+
Inside of your Astro project, you'll see the following folders and files:
18+
19+
```text
20+
/
21+
├── public/
22+
│ └── favicon.svg
23+
├── src/
24+
│ ├── layouts/
25+
│ │ └── Layout.astro
26+
│ └── pages/
27+
│ └── index.astro
28+
└── package.json
29+
```
30+
31+
To learn more about the folder structure of an Astro project, refer to [our guide on project structure](https://docs.astro.build/en/basics/project-structure/).
32+
33+
## 🧞 Commands
34+
35+
All commands are run from the root of the project, from a terminal:
36+
37+
| Command | Action |
38+
| :------------------------ | :----------------------------------------------- |
39+
| `npm install` | Installs dependencies |
40+
| `npm run dev` | Starts local dev server at `localhost:4321` |
41+
| `npm run build` | Build your production site to `./dist/` |
42+
| `npm run preview` | Preview your build locally, before deploying |
43+
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
44+
| `npm run astro -- --help` | Get help using the Astro CLI |
45+
46+
## 👀 Want to learn more?
47+
48+
Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @ts-check
2+
import { defineConfig } from "astro/config";
3+
4+
// https://astro.build/config
5+
export default defineConfig({
6+
output: "server",
7+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "astro-previews-example-app",
3+
"description": "A template for Astro with WordPress and URQL",
4+
"type": "module",
5+
"version": "0.0.1",
6+
"scripts": {
7+
"dev": "astro dev",
8+
"build": "astro build",
9+
"preview": "astro preview",
10+
"astro": "astro"
11+
},
12+
"dependencies": {
13+
"@urql/core": "^5.1.1",
14+
"astro": "^5.6.1"
15+
}
16+
}
Lines changed: 9 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
/**
3+
* We've hard coded this but you can use the client to fetch this data from WP Menus!
4+
* import { client, gql } from "../lib/client";
5+
*/
6+
---
7+
8+
<nav>
9+
<ul>
10+
<li>
11+
<a href="/">Home</a>
12+
</li>
13+
<li>
14+
<a href="/sample-page">Sample Page</a>
15+
</li>
16+
</ul>
17+
</nav>
18+
<style>
19+
nav {
20+
background: #eee;
21+
padding: 1rem;
22+
}
23+
nav ul {
24+
list-style: none;
25+
display: flex;
26+
gap: 1rem;
27+
}
28+
nav a {
29+
text-decoration: none;
30+
color: #333;
31+
}
32+
nav a:hover {
33+
text-decoration: underline;
34+
}
35+
nav a:visited {
36+
color: #666;
37+
}
38+
nav a:active {
39+
color: #000;
40+
}
41+
nav a:focus {
42+
outline: 2px solid #000;
43+
}
44+
nav a:focus-visible {
45+
outline: 2px solid #000;
46+
}
47+
nav a:focus:not(:focus-visible) {
48+
outline: none;
49+
}
50+
</style>

0 commit comments

Comments
 (0)