You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2021/11/04 09:18:25 UTC
[apisix-website] branch master updated: fix: update sitemap.xml's
loc (#708)
This is an automated email from the ASF dual-hosted git repository.
juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-website.git
The following commit(s) were added to refs/heads/master by this push:
new f169040 fix: update sitemap.xml's loc (#708)
f169040 is described below
commit f169040c9621a9171480c444353c83beb3c95758
Author: 琚致远 <ju...@apache.org>
AuthorDate: Thu Nov 4 17:18:19 2021 +0800
fix: update sitemap.xml's loc (#708)
---
.github/workflows/deploy.yml | 4 ++++
.gitignore | 2 ++
scripts/package.json | 5 +++--
scripts/update-sitemap-loc.js | 31 +++++++++++++++++++++++++++++++
4 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index cd00623..d25eb49 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -42,6 +42,10 @@ jobs:
cd website && yarn build
cp ../.asf.yaml ./build
+ - name: Update sitemap.xml
+ run: |
+ cd scripts && node update-sitemap-loc.js && git status
+
- name: Deploy
uses: peaceiris/actions-gh-pages@v3.8.0
if: github.event_name == 'push' && github.ref == 'refs/heads/master' || github.event_name == 'schedule'
diff --git a/.gitignore b/.gitignore
index 224c31d..509ed88 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,3 +29,5 @@ tmp/*
# Local Netlify folder
.netlify
+
+scripts/yarn.lock
diff --git a/scripts/package.json b/scripts/package.json
index 8e8da7d..dd61dba 100644
--- a/scripts/package.json
+++ b/scripts/package.json
@@ -5,10 +5,11 @@
},
"devDependencies": {
"@types/node": "^14.17.21",
- "listr": "^0.14.3",
"axios": "^0.21.1",
+ "listr": "^0.14.3",
"replace-in-file": "^6.2.0",
+ "semver": "^7.3.5",
"simple-git": "^2.44.0",
- "semver": "^7.3.5"
+ "xml-js": "^1.6.11"
}
}
diff --git a/scripts/update-sitemap-loc.js b/scripts/update-sitemap-loc.js
new file mode 100644
index 0000000..681cc53
--- /dev/null
+++ b/scripts/update-sitemap-loc.js
@@ -0,0 +1,31 @@
+/**
+ * This script updates the sitemap.xml file with the correct location
+ * See https://github.com/apache/apisix-website/issues/705
+*/
+
+const convert = require('xml-js');
+const fs = require('fs');
+
+const SITEMAP_XML_PATH = '../website/build/sitemap.xml';
+try {
+ if (!fs.existsSync(SITEMAP_XML_PATH)) {
+ throw new Error(`${SITEMAP_XML_PATH} does not exist`);
+ }
+
+ const xml = fs.readFileSync(SITEMAP_XML_PATH, 'utf8');
+ const result = JSON.parse(convert.xml2json(xml, { compact: true }))
+ result.urlset.url = result.urlset.url.map(item => {
+ const targetLoc = item.loc._text.endsWith('/') ? item.loc._text : `${item.loc._text}/`;
+ return {
+ loc: {
+ _text: targetLoc,
+ },
+ changefreq: item.changefreq,
+ priority: item.priority,
+ }
+ })
+ fs.writeFileSync(SITEMAP_XML_PATH, convert.json2xml(result, { compact: true, spaces: 4 }), 'utf8');
+ console.log(`Updated ${SITEMAP_XML_PATH} successfully`);
+} catch (error) {
+ console.warn(error)
+}