Skip to content

Commit 9451c97

Browse files
committed
Revert deleted files, rename folder and update docs, update Comments Reply logic
1 parent fea569d commit 9451c97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+428
-165
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"phpVersion": "7.4",
3+
"plugins": [
4+
"https://github.com/wp-graphql/wp-graphql/releases/latest/download/wp-graphql.zip",
5+
"https://github.com/AdvancedCustomFields/acf/releases/download/6.3.12/advanced-custom-fields-6.3.12.zip",
6+
"https://github.com/wp-graphql/wpgraphql-acf/releases/latest/download/wpgraphql-acf.zip"
7+
],
8+
"config": {
9+
"WP_DEBUG": true,
10+
"SCRIPT_DEBUG": false,
11+
"GRAPHQL_DEBUG": true,
12+
"WP_DEBUG_LOG": true,
13+
"WP_DEBUG_DISPLAY": false,
14+
"SAVEQUERIES": false
15+
},
16+
"mappings": {
17+
"db": "./wp-env/db",
18+
"wp-content/uploads": "./wp-env/uploads",
19+
".htaccess": "./wp-env/setup/.htaccess"
20+
},
21+
"lifecycleScripts": {
22+
"afterStart": "wp-env run cli -- wp plugin update wpgraphql-acf && wp-env run cli -- wp rewrite structure '/%postname%/' && wp-env run cli -- wp rewrite flush"
23+
}
24+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import { XMLParser } from 'fast-xml-parser';
2+
3+
const wordpressUrl =
4+
(process.env.NEXT_PUBLIC_WORDPRESS_URL || "http://localhost:8888").trim();
5+
const frontEndUrl =
6+
(process.env.NEXT_PUBLIC_FRONTEND_URL || "http://localhost:3000").trim();
7+
8+
// Parser configuration
9+
const parserConfig = {
10+
ignoreAttributes: false,
11+
preserveOrder: false,
12+
unpairedTags: ['xml', 'xml-stylesheet'],
13+
processEntities: true,
14+
htmlEntities: true,
15+
};
16+
17+
function trimSlashes(str) {
18+
return str.replace(/^\/+|\/+$/g, '');
19+
}
20+
21+
function createSitemap(urls) {
22+
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
23+
<?xml-stylesheet type="text/xsl" href="${frontEndUrl}/sitemap.xsl"?>
24+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
25+
${urls.map(url => `
26+
<url>
27+
<loc>${url.loc}</loc>
28+
${url.lastmod ? `<lastmod>${url.lastmod}</lastmod>` : ''}
29+
${url.changefreq ? `<changefreq>${url.changefreq}</changefreq>` : ''}
30+
${url.priority ? `<priority>${url.priority}</priority>` : ''}
31+
</url>`).join('')}
32+
</urlset>`;
33+
34+
return sitemap;
35+
}
36+
37+
function createSitemapIndex(sitemaps) {
38+
const sitemapIndex = `<?xml version="1.0" encoding="UTF-8"?>
39+
<?xml-stylesheet type="text/xsl" href="${frontEndUrl}/sitemap.xsl"?>
40+
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
41+
${sitemaps.map(sitemap => `
42+
<sitemap>
43+
<loc data-real-url="${sitemap.realUrl || sitemap.loc}">${sitemap.loc}</loc>
44+
${sitemap.lastmod ? `<lastmod>${sitemap.lastmod}</lastmod>` : ''}
45+
</sitemap>`).join('')}
46+
</sitemapindex>`;
47+
48+
return sitemapIndex;
49+
}
50+
51+
export async function getServerSideProps({ req, res }) {
52+
const url = new URL(req.url, `http://${req.headers.host}`);
53+
const sitemapParam = url.searchParams.get("sitemap");
54+
55+
const wpSitemapUrl = sitemapParam
56+
? `${trimSlashes(wordpressUrl)}/${sitemapParam.replace(/^\/+/, '')}`
57+
: `${trimSlashes(wordpressUrl)}/sitemap.xml`;
58+
59+
console.debug("Fetching sitemap", wpSitemapUrl);
60+
const response = await fetch(wpSitemapUrl);
61+
62+
if (!response.ok) {
63+
return { notFound: true };
64+
}
65+
66+
const xmlText = await response.text();
67+
const isIndex = xmlText.includes("<sitemapindex");
68+
const parser = new XMLParser({
69+
...parserConfig,
70+
isArray: (tagName) => tagName === (isIndex ? 'sitemap' : 'url'),
71+
});
72+
73+
const parsedXml = parser.parse(xmlText);
74+
75+
if (isIndex) {
76+
const wpSitemaps = parsedXml?.sitemapindex?.sitemap;
77+
if (!wpSitemaps) return { notFound: true };
78+
79+
const sitemaps = wpSitemaps.map(sitemap => {
80+
const url = new URL(sitemap.loc);
81+
const wpPath = url.pathname;
82+
const filenameMatch = wpPath.match(/\/([^\/]+)\.xml$/);
83+
84+
let displayLoc = filenameMatch && filenameMatch[1]
85+
? `${trimSlashes(frontEndUrl)}/sitemaps/${filenameMatch[1]}`
86+
: `${trimSlashes(frontEndUrl)}/sitemap.xml?sitemap=${wpPath}`;
87+
88+
return {
89+
...sitemap,
90+
loc: displayLoc,
91+
realUrl: `${trimSlashes(frontEndUrl)}/sitemap.xml?sitemap=${wpPath}`
92+
};
93+
});
94+
95+
const updatedXml = createSitemapIndex(sitemaps);
96+
res.setHeader("Content-Type", "application/xml");
97+
res.write(updatedXml);
98+
res.end();
99+
} else {
100+
const wpUrls = parsedXml?.urlset?.url;
101+
if (!wpUrls) return { notFound: true };
102+
103+
const urls = wpUrls.map(url => ({
104+
...url,
105+
loc: url.loc.replace(trimSlashes(wordpressUrl), trimSlashes(frontEndUrl))
106+
}));
107+
108+
const updatedXml = createSitemap(urls);
109+
res.setHeader("Content-Type", "application/xml");
110+
res.write(updatedXml);
111+
res.end();
112+
}
113+
114+
return { props: {} };
115+
}
116+
117+
export default function Sitemap() {
118+
return null;
119+
}

examples/nuxt/data-fetch/example-app/components/templates/comments/CommentItem.vue

Lines changed: 0 additions & 59 deletions
This file was deleted.

examples/nuxt/data-fetch/.wp-env.json renamed to examples/nuxt/template-hierarchy-data-fetching/.wp-env.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
],
1111
"env": {
1212
"development": {
13-
"port": 8890,
14-
"mysqlPort": 55090
13+
"port": 8890
1514
},
1615
"tests": {
17-
"port": 8891,
18-
"mysqlPort": 55091
16+
"port": 8891
1917
}
2018
},
2119
"config": {

examples/nuxt/data-fetch/README.md renamed to examples/nuxt/template-hierarchy-data-fetching/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Nuxt Data fetching
22

3-
In this example we show how to implement the WP Template Hierarchy in Nuxt for use with a Headless WordPress backend using WPGraphQL.
3+
In this example we show how to implement the WP Template Hierarchy and Data Fetching in Nuxt for use with a Headless WordPress backend using WPGraphQL.
44

55
## Getting Started
66

File renamed without changes.

0 commit comments

Comments
 (0)