@wpnuxt/core 1.0.0-edge.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +89 -0
  2. package/dist/module.cjs +5 -0
  3. package/dist/module.d.mts +116 -0
  4. package/dist/module.d.ts +116 -0
  5. package/dist/module.json +10 -0
  6. package/dist/module.mjs +357 -0
  7. package/dist/runtime/app/graphqlMiddleware.serverOptions.d.ts +2 -0
  8. package/dist/runtime/app/graphqlMiddleware.serverOptions.js +11 -0
  9. package/dist/runtime/components/StagingBanner.vue +107 -0
  10. package/dist/runtime/components/WPNuxtLogo.vue +17 -0
  11. package/dist/runtime/components/WordPressLogo.vue +15 -0
  12. package/dist/runtime/composables/index.d.ts +3 -0
  13. package/dist/runtime/composables/index.js +3 -0
  14. package/dist/runtime/composables/isStaging.d.ts +1 -0
  15. package/dist/runtime/composables/isStaging.js +6 -0
  16. package/dist/runtime/composables/useFeaturedImage.d.ts +2 -0
  17. package/dist/runtime/composables/useFeaturedImage.js +7 -0
  18. package/dist/runtime/composables/usePrevNextPost.d.ts +4 -0
  19. package/dist/runtime/composables/usePrevNextPost.js +25 -0
  20. package/dist/runtime/composables/useWPContent.d.ts +3 -0
  21. package/dist/runtime/composables/useWPContent.js +35 -0
  22. package/dist/runtime/composables/useWPUri.d.ts +8 -0
  23. package/dist/runtime/composables/useWPUri.js +23 -0
  24. package/dist/runtime/plugins/vue-sanitize-directive.d.ts +2 -0
  25. package/dist/runtime/plugins/vue-sanitize-directive.js +5 -0
  26. package/dist/runtime/queries/GeneralSettings.gql +7 -0
  27. package/dist/runtime/queries/Menu.gql +11 -0
  28. package/dist/runtime/queries/Node.gql +9 -0
  29. package/dist/runtime/queries/Pages.gql +19 -0
  30. package/dist/runtime/queries/Posts.gql +19 -0
  31. package/dist/runtime/queries/Revisions.gql +9 -0
  32. package/dist/runtime/queries/Viewer.gql +14 -0
  33. package/dist/runtime/queries/fragments/ContentNode.fragment.gql +28 -0
  34. package/dist/runtime/queries/fragments/GeneralSettings.fragment.gql +11 -0
  35. package/dist/runtime/queries/fragments/MediaItem.fragment.gql +52 -0
  36. package/dist/runtime/queries/fragments/MenuItem.fragment.gql +4 -0
  37. package/dist/runtime/queries/fragments/NodeWithExcerpt.fragment.gql +3 -0
  38. package/dist/runtime/queries/fragments/NodeWithFeaturedImage.fragment.gql +10 -0
  39. package/dist/runtime/queries/fragments/NodeWithFeaturedImageToMediaItemConnectionEdge.fragment.gql +8 -0
  40. package/dist/runtime/queries/fragments/Page.fragment.gql +15 -0
  41. package/dist/runtime/queries/fragments/Post.fragment.gql +11 -0
  42. package/dist/runtime/server/api/purgeCache.get.d.ts +5 -0
  43. package/dist/runtime/server/api/purgeCache.get.js +9 -0
  44. package/dist/runtime/server/api/wpContent.post.d.ts +9 -0
  45. package/dist/runtime/server/api/wpContent.post.js +50 -0
  46. package/dist/runtime/server/index.d.ts +1 -0
  47. package/dist/runtime/server/index.js +8 -0
  48. package/dist/runtime/server/storage.d.ts +3 -0
  49. package/dist/runtime/server/storage.js +11 -0
  50. package/dist/runtime/util/images.d.ts +2 -0
  51. package/dist/runtime/util/images.js +8 -0
  52. package/dist/runtime/util/logger.d.ts +3 -0
  53. package/dist/runtime/util/logger.js +25 -0
  54. package/dist/types.d.mts +7 -0
  55. package/dist/types.d.ts +7 -0
  56. package/package.json +100 -0
@@ -0,0 +1,11 @@
1
+ import { defineGraphqlServerOptions } from "nuxt-graphql-middleware/dist/runtime/serverOptions";
2
+ import { getHeader } from "h3";
3
+ export default defineGraphqlServerOptions({
4
+ serverFetchOptions(event) {
5
+ return {
6
+ headers: {
7
+ Authorization: getHeader(event, "Authorization")
8
+ }
9
+ };
10
+ }
11
+ });
@@ -0,0 +1,107 @@
1
+ <script setup lang="ts">
2
+ import { useWPUri } from '../composables/useWPUri'
3
+ import { useWPContent } from '../composables'
4
+ import WPNuxtLogo from './WPNuxtLogo.vue'
5
+ import WordPressLogo from './WordPressLogo.vue'
6
+ import { useRuntimeConfig, useHead, useRoute } from '#imports'
7
+
8
+ const config = useRuntimeConfig()
9
+ const frontendUrl = config.public.wpNuxt.frontendUrl
10
+ const wordpressUrl = config.public.wpNuxt.wordpressUrl
11
+ const wpUri = useWPUri()
12
+ useHead({
13
+ title: 'Staging',
14
+ link: [
15
+ {
16
+ type: 'stylesheet',
17
+ href: wordpressUrl + '/wp-admin/load-styles.php?c=0&dir=ltr&load%5Bchunk_0%5D=dashicons,admin-bar,site-health,common,forms,admin-menu,dashboard,list-tables,edit,revisions,media,themes,about,nav-menus,wp-poi&load%5Bchunk_1%5D=nter,widgets,site-icon,l10n,buttons,wp-auth-check&ver=6.4.3'
18
+ }
19
+ ]
20
+ })
21
+
22
+ const route = useRoute()
23
+ let uri = route.path === '/' ? 'home' : route.path
24
+ if (uri.startsWith('/')) {
25
+ uri = uri.substring(1)
26
+ }
27
+ if (uri.endsWith('/')) {
28
+ uri = uri.substring(0, uri.length - 1)
29
+ }
30
+ const { data: post } = await useWPContent('NodeByUri', ['nodeByUri'], false, { uri: uri })
31
+
32
+ if (import.meta.client) {
33
+ document.body.style.marginBottom = '40px'
34
+ }
35
+ </script>
36
+
37
+ <template>
38
+ <div id="wpNuxtStagingBar">
39
+ <div class="bar-container">
40
+ <div class="bar-left">
41
+ <WPNuxtLogo wp-color="white" />
42
+ <div class="bar-button-wrapper">
43
+ <NuxtLink
44
+ :to="wpUri.admin"
45
+ class="bar-button"
46
+ >
47
+ <WordPressLogo /> Admin
48
+ </NuxtLink>
49
+ </div>
50
+ <div
51
+ v-if="post"
52
+ class="bar-button-wrapper"
53
+ >
54
+ <NuxtLink
55
+ :to="wpUri.postEdit('' + post.databaseId)"
56
+ class="bar-button primary"
57
+ >
58
+ <svg
59
+ class="icon"
60
+ xmlns="http://www.w3.org/2000/svg"
61
+ viewBox="0 0 24 24"
62
+ width="24"
63
+ height="24"
64
+ >
65
+ <path
66
+ fill="none"
67
+ stroke-linecap="round"
68
+ stroke-linejoin="round"
69
+ stroke-width="1.5"
70
+ d="m16.862 4.487l1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L6.832 19.82a4.5 4.5 0 0 1-1.897 1.13l-2.685.8l.8-2.685a4.5 4.5 0 0 1 1.13-1.897zm0 0L19.5 7.125"
71
+ />
72
+ </svg>
73
+ Edit <span class="hidden sm:inline-flex">{{ post.contentTypeName }}</span>
74
+ </NuxtLink>
75
+ </div>
76
+ </div>
77
+ <div class="bar-right">
78
+ <div class="bar-button-wrapper">
79
+ <NuxtLink
80
+ v-if="frontendUrl"
81
+ :to="frontendUrl"
82
+ class="bar-button"
83
+ target="_blank"
84
+ >
85
+ Live site
86
+ <svg
87
+ class="icon"
88
+ xmlns="http://www.w3.org/2000/svg"
89
+ viewBox="0 0 24 24"
90
+ width="24"
91
+ height="24"
92
+ >
93
+ <path
94
+ fill="black"
95
+ d="M18 10.82a1 1 0 0 0-1 1V19a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V8a1 1 0 0 1 1-1h7.18a1 1 0 0 0 0-2H5a3 3 0 0 0-3 3v11a3 3 0 0 0 3 3h11a3 3 0 0 0 3-3v-7.18a1 1 0 0 0-1-1m3.92-8.2a1 1 0 0 0-.54-.54A1 1 0 0 0 21 2h-6a1 1 0 0 0 0 2h3.59L8.29 14.29a1 1 0 0 0 0 1.42a1 1 0 0 0 1.42 0L20 5.41V9a1 1 0 0 0 2 0V3a1 1 0 0 0-.08-.38"
96
+ />
97
+ </svg>
98
+ </NuxtLink>
99
+ </div>
100
+ </div>
101
+ </div>
102
+ </div>
103
+ </template>
104
+
105
+ <style scoped>
106
+ #wpNuxtStagingBar{background-color:#171717;height:40px;width:100%;--tw-shadow:0 -1px 10px -3px rgb(0,0,0,0.3);--tw-shadow-colored:0 -1px 10px -3px var(--tw-shadow-color);bottom:0;box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow);left:0;position:fixed;right:0;z-index:9999}#wpNuxtStagingBar .bar-container{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));margin-left:auto;margin-right:auto;max-width:80rem;padding:7px}#wpNuxtStagingBar .bar-left{text-align:left}#wpNuxtStagingBar .bar-left,#wpNuxtStagingBar .bar-right{display:flex;flex-grow:1;overflow:hidden;vertical-align:top}#wpNuxtStagingBar .bar-right{flex:none;justify-content:flex-end;text-align:right}.wpnuxt-logo{margin-right:1.5rem}.wordpress-logo{height:1rem;width:1rem}.bar-button{--tw-ring-color:#ccc;--tw-ring-inset:inset;--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000);--tw-text-opacity:1;align-items:center;background-color:#eee;border-radius:.375rem;color:#000;-moz-column-gap:.25rem;column-gap:.25rem;display:inline-flex;flex-shrink:0;font-size:.75rem;font-weight:500;line-height:1rem;margin-right:.5rem;padding:.25rem .5rem;stroke:#000;text-decoration:none}.bar-button:hover{--tw-ring-color:#999;background-color:#aaa;text-decoration:none}.bar-button.primary{--tw-ring-color:#999;background-color:rgb(186 175 78/var(--tw-text-opacity))}.bar-button.primary:hover{color:#fff;stroke:#fff;--tw-ring-color:#666;background-color:rgb(156 142 27/var(--tw-text-opacity));text-decoration:none}.bar-button-wrapper{display:inline-block;margin-top:.25rem;vertical-align:top}.icon{background-color:transparent;display:inline-block;height:1em;width:1em}
107
+ </style>
@@ -0,0 +1,17 @@
1
+ <script setup lang="ts">
2
+ const props = defineProps<{
3
+ wpColor?: string
4
+ }>()
5
+ const wpLight = props.wpColor ? props.wpColor : 'back'
6
+ const wpDark = props.wpColor ? props.wpColor : 'white'
7
+ </script>
8
+
9
+ <template>
10
+ <div class="wpnuxt-logo">
11
+ <span class="wpnuxt-logo-wp">WP</span><span class="wpnuxt-logo-nuxt">Nuxt</span>
12
+ </div>
13
+ </template>
14
+
15
+ <style scoped>
16
+ .wpnuxt-logo{display:none;font-size:1.5rem;font-weight:700;line-height:2rem}@media (min-width:640px){.wpnuxt-logo{display:inline-flex}}.wpnuxt-logo-wp{color:v-bind(wpLight);font-family:ui-serif,Times,serif}html.dark .wpnuxt-logo-wp{color:v-bind(wpDark);font-family:ui-serif,Times,serif}.wpnuxt-logo-nuxt{margin-top:-1px;--tw-text-opacity:1;color:rgb(186 175 78/var(--tw-text-opacity))}
17
+ </style>
@@ -0,0 +1,15 @@
1
+ <template>
2
+ <svg
3
+ class="wordpress-logo"
4
+ viewBox="0 0 122.52 122.523"
5
+ xmlns="http://www.w3.org/2000/svg"
6
+ >
7
+ <g fill="black">
8
+ <path d="m8.708 61.26c0 20.802 12.089 38.779 29.619 47.298l-25.069-68.686c-2.916 6.536-4.55 13.769-4.55 21.388z" />
9
+ <path d="m96.74 58.608c0-6.495-2.333-10.993-4.334-14.494-2.664-4.329-5.161-7.995-5.161-12.324 0-4.831 3.664-9.328 8.825-9.328.233 0 .454.029.681.042-9.35-8.566-21.807-13.796-35.489-13.796-18.36 0-34.513 9.42-43.91 23.688 1.233.037 2.395.063 3.382.063 5.497 0 14.006-.667 14.006-.667 2.833-.167 3.167 3.994.337 4.329 0 0-2.847.335-6.015.501l19.138 56.925 11.501-34.493-8.188-22.434c-2.83-.166-5.511-.501-5.511-.501-2.832-.166-2.5-4.496.332-4.329 0 0 8.679.667 13.843.667 5.496 0 14.006-.667 14.006-.667 2.835-.167 3.168 3.994.337 4.329 0 0-2.853.335-6.015.501l18.992 56.494 5.242-17.517c2.272-7.269 4.001-12.49 4.001-16.989z" />
10
+ <path d="m62.184 65.857-15.768 45.819c4.708 1.384 9.687 2.141 14.846 2.141 6.12 0 11.989-1.058 17.452-2.979-.141-.225-.269-.464-.374-.724z" />
11
+ <path d="m107.376 36.046c.226 1.674.354 3.471.354 5.404 0 5.333-.996 11.328-3.996 18.824l-16.053 46.413c15.624-9.111 26.133-26.038 26.133-45.426.001-9.137-2.333-17.729-6.438-25.215z" />
12
+ <path d="m61.262 0c-33.779 0-61.262 27.481-61.262 61.26 0 33.783 27.483 61.263 61.262 61.263 33.778 0 61.265-27.48 61.265-61.263-.001-33.779-27.487-61.26-61.265-61.26zm0 119.715c-32.23 0-58.453-26.223-58.453-58.455 0-32.23 26.222-58.451 58.453-58.451 32.229 0 58.45 26.221 58.45 58.451 0 32.232-26.221 58.455-58.45 58.455z" />
13
+ </g>
14
+ </svg>
15
+ </template>
@@ -0,0 +1,3 @@
1
+ export { isStaging } from './isStaging.js';
2
+ export { useWPContent } from './useWPContent.js';
3
+ export { useWPUri } from './useWPUri.js';
@@ -0,0 +1,3 @@
1
+ export { isStaging } from "./isStaging.js";
2
+ export { useWPContent } from "./useWPContent.js";
3
+ export { useWPUri } from "./useWPUri.js";
@@ -0,0 +1 @@
1
+ export declare const isStaging: () => Promise<any>;
@@ -0,0 +1,6 @@
1
+ import { useRuntimeConfig } from "#imports";
2
+ const _isStaging = async () => {
3
+ const config = useRuntimeConfig();
4
+ return config.public.wpNuxt.staging;
5
+ };
6
+ export const isStaging = _isStaging;
@@ -0,0 +1,2 @@
1
+ import type { Post, Page } from '#graphql-operations';
2
+ export declare const useFeaturedImage: (contentNode: Post | Page) => string | undefined;
@@ -0,0 +1,7 @@
1
+ import { getRelativeImagePath } from "../util/images.js";
2
+ const _useFeaturedImage = (contentNode) => {
3
+ const sourceUrl = contentNode?.featuredImage?.node?.sourceUrl;
4
+ if (sourceUrl) return getRelativeImagePath(sourceUrl);
5
+ else return void 0;
6
+ };
7
+ export const useFeaturedImage = _useFeaturedImage;
@@ -0,0 +1,4 @@
1
+ export declare const usePrevNextPost: (currentPostSlug: string) => Promise<{
2
+ prev: any;
3
+ next: any;
4
+ }>;
@@ -0,0 +1,25 @@
1
+ import { useWPContent } from "./useWPContent.js";
2
+ const _usePrevNextPost = async (currentPostSlug) => {
3
+ const allPosts = await getAllPosts();
4
+ if (!allPosts) return { prev: null, next: null };
5
+ const currentIndex = allPosts.slugs.findIndex((slug) => slug === currentPostSlug);
6
+ const nextPost = currentIndex > 0 ? allPosts.slugs[currentIndex - 1] : null;
7
+ const prevPost = allPosts.slugs.length > currentIndex + 1 ? allPosts.slugs[currentIndex + 1] : null;
8
+ return {
9
+ prev: prevPost ? prevPost : null,
10
+ next: nextPost ? nextPost : null
11
+ };
12
+ };
13
+ const getAllPosts = async () => {
14
+ const { data: allPosts } = await useWPContent("Posts", ["posts", "nodes"], false);
15
+ if (allPosts.value) {
16
+ return {
17
+ slugs: allPosts.value?.map((post) => {
18
+ if (post) return post.slug;
19
+ else return null;
20
+ })
21
+ };
22
+ }
23
+ return;
24
+ };
25
+ export const usePrevNextPost = _usePrevNextPost;
@@ -0,0 +1,3 @@
1
+ import { FetchError } from 'ofetch';
2
+ import { type AsyncData } from '#app';
3
+ export declare const useWPContent: <T>(queryName: string, nodes: string[], fixImagePaths: boolean, params?: T) => Promise<AsyncData<T, FetchError | null>>;
@@ -0,0 +1,35 @@
1
+ import { FetchError } from "ofetch";
2
+ import { getRelativeImagePath } from "../util/images.js";
3
+ import { useFetch, useNuxtApp } from "#app";
4
+ const _useWPContent = async (queryName, nodes, fixImagePaths, params) => {
5
+ const nuxtApp = useNuxtApp();
6
+ const cacheKey = `wp-${queryName}-${nodes}-${JSON.stringify(params)}`;
7
+ return useFetch("/api/wpContent", {
8
+ method: "POST",
9
+ body: {
10
+ queryName,
11
+ params
12
+ },
13
+ key: cacheKey,
14
+ transform(data) {
15
+ const transformedData = findData(data.data, nodes);
16
+ if (fixImagePaths && transformedData?.featuredImage?.node?.sourceUrl) {
17
+ transformedData.featuredImage.node.relativePath = getRelativeImagePath(transformedData.featuredImage.node.sourceUrl);
18
+ }
19
+ if (transformedData) return transformedData;
20
+ throw new FetchError("No data found");
21
+ },
22
+ getCachedData(key) {
23
+ return nuxtApp.payload.data[key] || nuxtApp.static.data[key];
24
+ }
25
+ });
26
+ };
27
+ const findData = (data, nodes) => {
28
+ if (nodes.length === 0) return data;
29
+ if (nodes.length > 0) {
30
+ return nodes.reduce((acc, node) => {
31
+ return acc[node];
32
+ }, data);
33
+ }
34
+ };
35
+ export const useWPContent = _useWPContent;
@@ -0,0 +1,8 @@
1
+ export declare const useWPUri: () => {
2
+ base: any;
3
+ admin: string;
4
+ pagesAdmin: string;
5
+ postAdmin: string;
6
+ postEdit: (path: string) => string;
7
+ settingsEdit: string;
8
+ };
@@ -0,0 +1,23 @@
1
+ import { useRuntimeConfig } from "#imports";
2
+ const _useWPUri = () => {
3
+ const config = useRuntimeConfig();
4
+ const base = config.public.wpNuxt.wordpressUrl;
5
+ const admin = base + "/wp-admin";
6
+ const pagesAdmin = base + "/wp-admin/edit.php?post_type=page";
7
+ const postAdmin = base + "/wp-admin/edit.php?post_type=post";
8
+ const settingsEdit = base + "/wp-admin/options-general.php";
9
+ const postEdit = (path) => {
10
+ if (path)
11
+ return base + "/wp-admin/post.php?post=" + path + "&action=edit";
12
+ else return postAdmin;
13
+ };
14
+ return {
15
+ base,
16
+ admin,
17
+ pagesAdmin,
18
+ postAdmin,
19
+ postEdit,
20
+ settingsEdit
21
+ };
22
+ };
23
+ export const useWPUri = _useWPUri;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import { defineNuxtPlugin } from "nuxt/app";
2
+ import VueSanitize from "vue-sanitize-directive";
3
+ export default defineNuxtPlugin((nuxtApp) => {
4
+ nuxtApp.vueApp.use(VueSanitize);
5
+ });
@@ -0,0 +1,7 @@
1
+ #import "~/.queries/fragments/GeneralSettings.fragment.gql"
2
+
3
+ query GeneralSettings {
4
+ generalSettings {
5
+ ...GeneralSettings
6
+ }
7
+ }
@@ -0,0 +1,11 @@
1
+ #import "~/.queries/fragments/MenuItem.fragment.gql"
2
+
3
+ query Menu($name: ID! = "main", $idType: MenuNodeIdTypeEnum! = NAME) {
4
+ menu(id: $name, idType: $idType) {
5
+ menuItems {
6
+ nodes {
7
+ ...MenuItem
8
+ }
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,9 @@
1
+ #import "~/.queries/fragments/Page.fragment.gql"
2
+ #import "~/.queries/fragments/Post.fragment.gql"
3
+
4
+ query NodeByUri($uri: String!) {
5
+ nodeByUri(uri: $uri) {
6
+ ...Page
7
+ ...Post
8
+ }
9
+ }
@@ -0,0 +1,19 @@
1
+ #import "~/.queries/fragments/Page.fragment.gql"
2
+
3
+ query Pages($limit: Int = 10) {
4
+ pages(first: $limit) {
5
+ nodes {
6
+ ...Page
7
+ }
8
+ }
9
+ }
10
+ query PageByUri($uri: String!) {
11
+ nodeByUri(uri: $uri) {
12
+ ...Page
13
+ }
14
+ }
15
+ query PageById($id: ID!) {
16
+ page(id: $id, idType: DATABASE_ID, asPreview: true) {
17
+ ...Page
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ #import "~/.queries/fragments/Post.fragment.gql"
2
+
3
+ query Posts($limit: Int = 10) {
4
+ posts(first: $limit) {
5
+ nodes {
6
+ ...Post
7
+ }
8
+ }
9
+ }
10
+ query PostByUri($uri: String!) {
11
+ nodeByUri(uri: $uri) {
12
+ ...Post
13
+ }
14
+ }
15
+ query PostById($id: ID!, $asPreview: Boolean = false) {
16
+ post(id: $id, idType: DATABASE_ID, asPreview: $asPreview) {
17
+ ...Post
18
+ }
19
+ }
@@ -0,0 +1,9 @@
1
+ query Revisions {
2
+ revisions {
3
+ nodes {
4
+ date
5
+ uri
6
+ isPreview
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,14 @@
1
+ query Viewer {
2
+ viewer {
3
+ username
4
+ userId
5
+ id
6
+ email
7
+ description
8
+ firstName
9
+ lastName
10
+ locale
11
+ url
12
+ uri
13
+ }
14
+ }
@@ -0,0 +1,28 @@
1
+ fragment ContentNode on ContentNode {
2
+ # contentType
3
+ contentTypeName
4
+ databaseId
5
+ date
6
+ dateGmt
7
+ desiredSlug
8
+ # editingLockedBy
9
+ enclosure
10
+ # enqueuedScripts
11
+ # enqueuedStylesheets
12
+ guid
13
+ id
14
+ isContentNode
15
+ isPreview
16
+ isRestricted
17
+ isTermNode
18
+ # lastEditedBy
19
+ link
20
+ modified
21
+ modifiedGmt
22
+ previewRevisionDatabaseId
23
+ previewRevisionId
24
+ slug
25
+ status
26
+ # template
27
+ uri
28
+ }
@@ -0,0 +1,11 @@
1
+ fragment GeneralSettings on GeneralSettings {
2
+ title
3
+ description
4
+ url
5
+ email
6
+ dateFormat
7
+ language
8
+ startOfWeek
9
+ timezone
10
+ timeFormat
11
+ }
@@ -0,0 +1,52 @@
1
+ fragment MediaItem on MediaItem {
2
+ altText
3
+ # ancestors
4
+ # author
5
+ authorDatabaseId
6
+ authorId
7
+ caption
8
+ # children
9
+ commentCount
10
+ commentStatus
11
+ # comments
12
+ # contentType
13
+ contentTypeName
14
+ databaseId
15
+ date
16
+ dateGmt
17
+ description
18
+ desiredSlug
19
+ # editingLockedBy
20
+ enclosure
21
+ # enqueuedScripts
22
+ # enqueuedStylesheets
23
+ fileSize
24
+ guid
25
+ id
26
+ isContentNode
27
+ isPreview
28
+ isRestricted
29
+ isTermNode
30
+ # lastEditedBy
31
+ link
32
+ # mediaDetails
33
+ mediaItemId
34
+ mediaItemUrl
35
+ mediaType
36
+ mimeType
37
+ modified
38
+ modifiedGmt
39
+ # parent
40
+ parentDatabaseId
41
+ parentId
42
+ previewRevisionDatabaseId
43
+ previewRevisionId
44
+ sizes
45
+ slug
46
+ sourceUrl
47
+ srcSet
48
+ status
49
+ # template
50
+ title
51
+ uri
52
+ }
@@ -0,0 +1,4 @@
1
+ fragment MenuItem on MenuItem {
2
+ label
3
+ uri
4
+ }
@@ -0,0 +1,3 @@
1
+ fragment NodeWithExcerpt on NodeWithExcerpt {
2
+ excerpt
3
+ }
@@ -0,0 +1,10 @@
1
+ #import '~/.queries/fragments/NodeWithFeaturedImageToMediaItemConnectionEdge.fragment.gql';
2
+
3
+ fragment NodeWithFeaturedImage on NodeWithFeaturedImage {
4
+ featuredImage {
5
+ ...NodeWithFeaturedImageToMediaItemConnectionEdge
6
+ }
7
+ featuredImageDatabaseId
8
+ featuredImageId
9
+ id
10
+ }
@@ -0,0 +1,8 @@
1
+ #import '~/.queries/fragments/MediaItem.fragment.gql';
2
+
3
+ fragment NodeWithFeaturedImageToMediaItemConnectionEdge on NodeWithFeaturedImageToMediaItemConnectionEdge {
4
+ cursor
5
+ node {
6
+ ...MediaItem
7
+ }
8
+ }
@@ -0,0 +1,15 @@
1
+ #import '~/.queries/fragments/ContentNode.fragment.gql';
2
+ #import '~/.queries/fragments/NodeWithFeaturedImage.fragment.gql';
3
+
4
+ fragment Page on Page {
5
+ ...ContentNode
6
+ ...NodeWithFeaturedImage
7
+ content
8
+ isFrontPage
9
+ isPostsPage
10
+ isPreview
11
+ isPrivacyPage
12
+ isRestricted
13
+ isRevision
14
+ title
15
+ }
@@ -0,0 +1,11 @@
1
+ #import "~/.queries/fragments/NodeWithExcerpt.fragment.gql";
2
+ #import '~/.queries/fragments/ContentNode.fragment.gql';
3
+ #import '~/.queries/fragments/NodeWithFeaturedImage.fragment.gql';
4
+
5
+ fragment Post on Post {
6
+ ...NodeWithExcerpt
7
+ ...ContentNode
8
+ ...NodeWithFeaturedImage
9
+ content
10
+ title
11
+ }
@@ -0,0 +1,5 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
+ data: string;
3
+ errors: never[];
4
+ }>>;
5
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import { defineEventHandler } from "h3";
2
+ import { purgeCache } from "../storage.js";
3
+ export default defineEventHandler(async () => {
4
+ purgeCache();
5
+ return {
6
+ data: "Cache purged!",
7
+ errors: []
8
+ };
9
+ });
@@ -0,0 +1,9 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
+ data: any;
3
+ errors: any;
4
+ }>>;
5
+ export default _default;
6
+ /**
7
+ * Get the parameters for the GraphQL middleware query.
8
+ */
9
+ export declare function buildRequestParams(variables?: Record<string, any> | undefined | null): Record<string, any>;
@@ -0,0 +1,50 @@
1
+ import { defineEventHandler, readBody } from "h3";
2
+ import { cacheStorage } from "../storage.js";
3
+ import { isStaging } from "../../composables/isStaging.js";
4
+ import { useRuntimeConfig } from "#imports";
5
+ export default defineEventHandler(async (event) => {
6
+ const config = useRuntimeConfig();
7
+ const body = await readBody(event);
8
+ const staging = await isStaging();
9
+ if (!body || !body.queryName) {
10
+ throw new Error(
11
+ "The request must contain a queryName"
12
+ );
13
+ }
14
+ const cacheKey = `wpContent-${body.queryName}-${body.params ? JSON.stringify(body.params).replaceAll('"', "").replaceAll(":", "-") : ""}`;
15
+ if (config.public.wpNuxt.enableCache && !staging) {
16
+ const cachedContent = await cacheStorage.getItem(cacheKey);
17
+ if (cachedContent) {
18
+ return {
19
+ data: cachedContent,
20
+ errors: []
21
+ };
22
+ }
23
+ }
24
+ return $fetch("/api/graphql_middleware/query/" + body.queryName, {
25
+ params: buildRequestParams(body.params),
26
+ headers: {
27
+ Authorization: `Bearer ${event.context.accessToken}`
28
+ }
29
+ }).then((v) => {
30
+ cacheStorage.setItem(cacheKey, v.data).catch(() => {
31
+ });
32
+ return {
33
+ data: v.data,
34
+ errors: v.errors || []
35
+ };
36
+ });
37
+ });
38
+ export function buildRequestParams(variables) {
39
+ if (!variables) {
40
+ return {};
41
+ }
42
+ for (const key in variables) {
43
+ if (typeof variables[key] !== "string") {
44
+ return {
45
+ __variables: JSON.stringify(variables)
46
+ };
47
+ }
48
+ }
49
+ return variables;
50
+ }
@@ -0,0 +1 @@
1
+ export declare function usePosts(): Promise<unknown>;
@@ -0,0 +1,8 @@
1
+ export function usePosts() {
2
+ return $fetch("/api/wpContent", {
3
+ method: "POST",
4
+ body: {
5
+ queryName: "Posts"
6
+ }
7
+ });
8
+ }