From 74bed78b93615395e4e9eb959a2da3a77b25e401 Mon Sep 17 00:00:00 2001 From: DanielHabenicht Date: Sat, 28 Nov 2020 19:19:55 +0100 Subject: [PATCH] feat: add seo relevant files (#376) * add robots.txt * add to hosting guide * add sitemap.xml and script --- create-sitemap.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ hosting/README.md | 10 ++++++++++ package.json | 2 ++ static/robots.txt | 2 ++ static/sitemap.xml | 1 + 5 files changed, 57 insertions(+) create mode 100644 create-sitemap.ts create mode 100644 static/robots.txt create mode 100644 static/sitemap.xml diff --git a/create-sitemap.ts b/create-sitemap.ts new file mode 100644 index 00000000..6667b4a4 --- /dev/null +++ b/create-sitemap.ts @@ -0,0 +1,42 @@ +import { sitemapBuilder as buildSitemap } from "react-router-sitemap"; + +var fs = require("fs"); + +const regex = /pages: (\[[\w\W]+?\])/gm; + +let source = regex.exec(fs.readFileSync("./apps/official/index.ts").toString())[1]; +//console.log(source); + +let ignorePaths = ["questions"]; +let pathPrefix = "/#/"; + +var paths = source + .split(",") + .map((x) => x.split(":").map((y) => y.trim())) + .reduce((a, x) => { + if (x[0] == "route") { + let route = x[1].replace(/["'/]/g, ""); + if (ignorePaths.findIndex((p) => route === p) == -1) { + a.push(pathPrefix + route); + } + } + return a; + }, []); + +const hostname = "https://www.covmap.de"; +const sitemap = buildSitemap(hostname, paths); +console.log(sitemap); + +const { createWriteStream } = require("fs"); +const { SitemapStream } = require("sitemap"); + +// Creates a sitemap object given the input configuration with URLs +const sitemapSteam = new SitemapStream(sitemap); + +const writeStream = createWriteStream("./static/sitemap.xml"); +sitemapSteam.pipe(writeStream); +paths.forEach((path) => { + sitemapSteam.write(path); +}); + +sitemapSteam.end(); diff --git a/hosting/README.md b/hosting/README.md index e795346c..6a117d96 100644 --- a/hosting/README.md +++ b/hosting/README.md @@ -1,3 +1,13 @@ +## Setup + +# Preparation + +Get a `Ubuntu 20.04.1 LTS` Server (e.g. 2 cores 4 GB RAM) + +1. [Install Docker](https://docs.docker.com/engine/install/ubuntu/) +2. [Install Docker Compose](https://docs.docker.com/compose/install/) +3. Clone this repo + # First Startup 1. `chmod +x setup.sh` diff --git a/package.json b/package.json index 915cb63d..510ffc63 100644 --- a/package.json +++ b/package.json @@ -95,10 +95,12 @@ "prettier": "2.1.2", "react-hot-loader": "^4.12.20", "react-map-gl": "^5.2.3", + "react-router-sitemap": "^1.2.0", "react-test-renderer": "^16.13.1", "redux-persist": "^6.0.0", "redux-persist-transform-filter": "^0.0.20", "semantic-release": "^17.2.1", + "sitemap": "^6.3.3", "style-loader": "^1.1.3", "testcafe": "^1.9.4", "testcafe-browser-provider-browserstack": "^1.13.1", diff --git a/static/robots.txt b/static/robots.txt new file mode 100644 index 00000000..0ad279c7 --- /dev/null +++ b/static/robots.txt @@ -0,0 +1,2 @@ +User-Agent: * +Disallow: diff --git a/static/sitemap.xml b/static/sitemap.xml new file mode 100644 index 00000000..778d8195 --- /dev/null +++ b/static/sitemap.xml @@ -0,0 +1 @@ +https://www.covmap.de/#/chartshttps://www.covmap.de/#/faqhttps://www.covmap.de/#/creditshttps://www.covmap.de/#/imprinthttps://www.covmap.de/#/legalhttps://www.covmap.de/#/privacy-statementhttps://www.covmap.de/#/recommendationshttps://www.covmap.de/#/rkihttps://www.covmap.de/#/contact-behaviorhttps://www.covmap.de/#/symptom-level \ No newline at end of file