Automatically rewrite links to localhost when developing on docs locally.

This commit is contained in:
Dan Helfman 2019-10-14 13:13:41 -07:00
parent 7b3b28616d
commit b1941bcce9
3 changed files with 10 additions and 4 deletions

View file

@ -16,7 +16,12 @@ module.exports = function(eleventyConfig) {
// Replace links to .md files with links to directories. This allows unparsed Markdown links // Replace links to .md files with links to directories. This allows unparsed Markdown links
// to work on GitHub, while rendered links elsewhere also work. // to work on GitHub, while rendered links elsewhere also work.
replaceLink: function (link, env) { replaceLink: function (link, env) {
return link.replace(/\.md$/, '/'); link = link.replace(/\.md$/, '/');
if (process.env.NODE_ENV == "production") {
return link;
}
return link.replace('https://torsion.org/borgmatic/', 'http://localhost:8080/');
} }
}; };
let markdownItAnchorOptions = { let markdownItAnchorOptions = {

View file

@ -9,6 +9,8 @@ RUN borgmatic --help > /command-line.txt \
FROM node:12.10.0-alpine as html FROM node:12.10.0-alpine as html
ARG ENVIRONMENT=production
WORKDIR /source WORKDIR /source
RUN npm install @11ty/eleventy \ RUN npm install @11ty/eleventy \
@ -20,7 +22,7 @@ RUN npm install @11ty/eleventy \
COPY --from=borgmatic /etc/borgmatic/config.yaml /source/docs/_includes/borgmatic/config.yaml COPY --from=borgmatic /etc/borgmatic/config.yaml /source/docs/_includes/borgmatic/config.yaml
COPY --from=borgmatic /command-line.txt /source/docs/_includes/borgmatic/command-line.txt COPY --from=borgmatic /command-line.txt /source/docs/_includes/borgmatic/command-line.txt
COPY . /source COPY . /source
RUN npx eleventy --input=/source/docs --output=/output/docs \ RUN NODE_ENV=${ENVIRONMENT} npx eleventy --input=/source/docs --output=/output/docs \
&& mv /output/docs/index.html /output/index.html && mv /output/docs/index.html /output/index.html
FROM nginx:1.16.1-alpine FROM nginx:1.16.1-alpine

View file

@ -2,9 +2,8 @@
set -e set -e
docker build --tag borgmatic-docs --file docs/Dockerfile . docker build --tag borgmatic-docs --build-arg ENVIRONMENT=dev --file docs/Dockerfile .
echo echo
echo "You can view dev docs at http://localhost:8080" echo "You can view dev docs at http://localhost:8080"
echo "Note that links within these docs will go to the online docs, so you will need to fiddle with URLs manually to stay in the dev docs."
echo echo
docker run --interactive --tty --publish 8080:80 --rm borgmatic-docs docker run --interactive --tty --publish 8080:80 --rm borgmatic-docs