From 437268370661087dbe31323efb18dfe1a518da33 Mon Sep 17 00:00:00 2001 From: flu0r1ne Date: Wed, 21 Jul 2021 03:59:15 -0500 Subject: Dynamic markdown page generation with preloading --- package-lock.json | 25 +- package.json | 1 + pages/logs/[directory].tsx | 58 +++++ pages/logs/cgit-nginx-ubuntu/cgit-nginx-ubuntu.md | 96 -------- pages/logs/cgit-nginx-ubuntu/index.tsx | 12 - pages/logs/packaging-nebula-for-debian/index.tsx | 12 - pages/logs/packaging-nebula-for-debian/nebula.md | 263 ---------------------- plugins/withMarkdownLoader.js | 12 +- posts/cgit-nginx-ubuntu/main.md | 96 ++++++++ posts/cgit-nginx-ubuntu/meta.json | 3 + posts/packaging-nebula-for-debian/main.md | 263 ++++++++++++++++++++++ posts/packaging-nebula-for-debian/meta.json | 3 + utils/Posts.tsx | 40 ++-- utils/markedOptions.js | 12 + 14 files changed, 482 insertions(+), 414 deletions(-) create mode 100644 pages/logs/[directory].tsx delete mode 100644 pages/logs/cgit-nginx-ubuntu/cgit-nginx-ubuntu.md delete mode 100644 pages/logs/cgit-nginx-ubuntu/index.tsx delete mode 100644 pages/logs/packaging-nebula-for-debian/index.tsx delete mode 100644 pages/logs/packaging-nebula-for-debian/nebula.md create mode 100644 posts/cgit-nginx-ubuntu/main.md create mode 100644 posts/cgit-nginx-ubuntu/meta.json create mode 100644 posts/packaging-nebula-for-debian/main.md create mode 100644 posts/packaging-nebula-for-debian/meta.json create mode 100644 utils/markedOptions.js diff --git a/package-lock.json b/package-lock.json index c833cb9..4a318a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "sass": "^1.35.2" }, "devDependencies": { + "@types/marked": "^2.0.4", "@types/react": "^17.0.14", "typescript": "4.3.5" } @@ -33,9 +34,9 @@ } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.14.5", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.14.5.tgz", - "integrity": "sha512-5lsetuxCLilmVGyiLEfoHBRX8UCFD+1m2x3Rj97WrW3V7H3u4RWRXA4evMjImCsin2J2YT0QaVDGf+z8ondbAg==", + "version": "7.14.8", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.14.8.tgz", + "integrity": "sha512-ZGy6/XQjllhYQrNw/3zfWRwZCTVSiBLZ9DHVZxn9n2gip/7ab8mv2TWlKPIBk26RwedCBoWdjLmn+t9na2Gcow==", "engines": { "node": ">=6.9.0" } @@ -240,6 +241,12 @@ "integrity": "sha512-YSBPTLTVm2e2OoQIDYx8HaeWJ5tTToLH67kXR7zYNGupXMEHa2++G8k+DczX2cFVgalypqtyZIcU19AFcmOpmg==", "peer": true }, + "node_modules/@types/marked": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@types/marked/-/marked-2.0.4.tgz", + "integrity": "sha512-L9VRSe0Id8xbPL99mUo/4aKgD7ZoRwFZqUQScNKHi2pFjF9ZYSMNShUHD6VlMT6J/prQq0T1mxuU25m3R7dFzg==", + "dev": true + }, "node_modules/@types/node": { "version": "16.3.3", "resolved": "https://registry.npmjs.org/@types/node/-/node-16.3.3.tgz", @@ -3550,9 +3557,9 @@ } }, "@babel/helper-validator-identifier": { - "version": "7.14.5", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.14.5.tgz", - "integrity": "sha512-5lsetuxCLilmVGyiLEfoHBRX8UCFD+1m2x3Rj97WrW3V7H3u4RWRXA4evMjImCsin2J2YT0QaVDGf+z8ondbAg==" + "version": "7.14.8", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.14.8.tgz", + "integrity": "sha512-ZGy6/XQjllhYQrNw/3zfWRwZCTVSiBLZ9DHVZxn9n2gip/7ab8mv2TWlKPIBk26RwedCBoWdjLmn+t9na2Gcow==" }, "@babel/highlight": { "version": "7.14.5", @@ -3720,6 +3727,12 @@ "integrity": "sha512-YSBPTLTVm2e2OoQIDYx8HaeWJ5tTToLH67kXR7zYNGupXMEHa2++G8k+DczX2cFVgalypqtyZIcU19AFcmOpmg==", "peer": true }, + "@types/marked": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@types/marked/-/marked-2.0.4.tgz", + "integrity": "sha512-L9VRSe0Id8xbPL99mUo/4aKgD7ZoRwFZqUQScNKHi2pFjF9ZYSMNShUHD6VlMT6J/prQq0T1mxuU25m3R7dFzg==", + "dev": true + }, "@types/node": { "version": "16.3.3", "resolved": "https://registry.npmjs.org/@types/node/-/node-16.3.3.tgz", diff --git a/package.json b/package.json index bceb376..eebfe19 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "sass": "^1.35.2" }, "devDependencies": { + "@types/marked": "^2.0.4", "@types/react": "^17.0.14", "typescript": "4.3.5" } diff --git a/pages/logs/[directory].tsx b/pages/logs/[directory].tsx new file mode 100644 index 0000000..00fe78d --- /dev/null +++ b/pages/logs/[directory].tsx @@ -0,0 +1,58 @@ +import path from 'path'; +import { GetStaticProps, GetStaticPropsContext } from 'next'; +import React, { FC } from 'react'; +import { getPosts, getMarkdown, Post, getPostFromDirectory } from '../../utils/Posts'; +import Markdown from '../../components/Markdown'; +import DefaultPage from '../../templates/Default'; + +interface Props { + post: Post; + markdown: string; +} + +const Page : FC = ({ post, markdown }) => { + return ( + <> + + + + + ); +} + +export default Page; + +export const getStaticProps: GetStaticProps = async ( + context: GetStaticPropsContext + ) => { + const directory = context.params!.directory as string; + + const post = await getPostFromDirectory(directory); + + const markdown = await getMarkdown(post); + + return { + props: { post, markdown }, + } +} + +export async function getStaticPaths() { + const posts = await getPosts(); + + const paths = posts.map((post) => { + return { + params: { + directory: post.directory + } + }; + }); + + return { + paths, + fallback: false + }; +} \ No newline at end of file diff --git a/pages/logs/cgit-nginx-ubuntu/cgit-nginx-ubuntu.md b/pages/logs/cgit-nginx-ubuntu/cgit-nginx-ubuntu.md deleted file mode 100644 index c225bd4..0000000 --- a/pages/logs/cgit-nginx-ubuntu/cgit-nginx-ubuntu.md +++ /dev/null @@ -1,96 +0,0 @@ -Installing cGit behind NGINX on Ubuntu -====================================== - -[cGit](https://git.zx2c4.com/cgit/about/) is a fast web interface based on the CGI specification. It is lightweight and doesn't require a database or web authentication system. - -It's easy to configure. For some reason, all the online guides for Ubuntu decided they needed to compile it from scratch and write their own start scripts in a mix of perl and bash. You don't need superhero sysadmin skills from the late 90s. All components are packaged with systemd units... there is a better way... - -### 1. Install `cgit` and `fcgiwrap`. - -`fcgiwrap` will create a socket NGINX can use to pass the CGI variables to cGit: -``` -sudo apt install fcgiwrap -sudo apt install cgit -``` - -### 2. Modify the `cgitrc` file under `/etc/cgitrc` to your liking: -``` -# See cgitrc(5) -# prepend this string to every url -virtual-root=/ -enable-index-links=1 -enable-commit-graph=1 - -root-title=My Git Repos -root-desc=I exclusivly write code in Smalltalk-71 -logo=/assets/my_custom_logo.png - -# Add site-specific configuration -# ... - -``` - -### 3. Optionally create an assets directory and add your custom logo / css: -``` -mkdir /var/www/html/assets -cp my_custom_logo.png /var/www/html/assets -``` - -### 4. Configure NGINX - -Add the site to NGINX. This launches the `cgit.cgi` executable passing it to the `fcgiwrap` socket: -```conf -echo >/etc/nginx/sites-available/cgit.conf < - ); -} \ No newline at end of file diff --git a/pages/logs/packaging-nebula-for-debian/index.tsx b/pages/logs/packaging-nebula-for-debian/index.tsx deleted file mode 100644 index a8e8e2c..0000000 --- a/pages/logs/packaging-nebula-for-debian/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -// @ts-ignore -import md from './nebula.md'; -import MarkdownPage from '../../../templates/MarkdownPage'; - -export default function NebulaOnDebian() { - return ( - - ); -} \ No newline at end of file diff --git a/pages/logs/packaging-nebula-for-debian/nebula.md b/pages/logs/packaging-nebula-for-debian/nebula.md deleted file mode 100644 index d1c178f..0000000 --- a/pages/logs/packaging-nebula-for-debian/nebula.md +++ /dev/null @@ -1,263 +0,0 @@ -Packaging Nebula for Debian -================= - -> **Created:** 2021-07-18 **Last Updated:** 2021-07-19 - -I am close to concluding a multi-week endevor to package [Nebula](https://github.com/slackhq/nebula), a VPN-style network mesh networking overlay. If all goes well, it will be uploaded to `debian/experimental` within the next few days. This would also mean the package would be pulled into Ubuntu during the next merge window. - -### Timeline - -Unfortunately, Debian does not adhere to a constant release cycle. This means the timeline is uncertain. It will likely be uploaded to `experimental` within a few days. [See the new queue.](https://ftp-master.debian.org/new.html) It will stay in experimental for the next three months or so until the next release occurs. (It is incompatible with the version of protobuf in unstable. This prevents it from moving into unstable until the next version release.) -``` -{upload queue} -> [experimental] -> [unstable (sid)] -> [testing] -> [next release] -``` - -Preemptively, I'm going to write up a set of install instructions specific to debian derivatives and briefly a few of the decisions made during the packaging process. - -Installation ------------- - -**Step one will currently fail. See [installing from experimental](#installing-from-experimental)** - -For the sake of simplicity, I'm going to assume that you're setting up a network with two nodes -- one lighthouse node and a node on your laptop. Once you understand the process, it easily scales to as many nodes as you wish. Pick your favorite virtualization provider in order to set up the lighthouse. The lighthouse requires minimal resources because it functions as a mutually-reachable node which synchronizes the address mappings. You could use a home server provided that you have a static ip (unlikely) or setup dynamic DNS. The latter may introduce some instability. I'm also assuming both clients are debian derivatives and have access to `apt`. - -If this is not the case, please consult the [upstream instructions](https://github.com/slackhq/nebula#user-content-getting-started-quickly) which will guide you through the processing of installing the binaries directly. - -#### 1. Install Nebula through Aptitude - -You'll need to install Nebula on both endpoints. - -```bash -sudo apt install nebula -``` - -#### 2. Creating a certificate authority - -The certificate authority is to "root of trust" for a Nebula network. Compromising the certificate authority's key file would compromise the integrity and security of the entire network. The upstream instructions recommend that you store the key file in a location with strong encryption [^1]. - -You can generate a `ca.key` and `ca.cert` file with the following command: -```bash -nebula-cert ca -name "Myorganization, Inc" -``` - -You will copy the `ca.crt` file to all the hosts. The `ca.key` file should remain secret. - -#### 4. Nebula host keys and certificates generated from that certificate authority - -With your `ca.key` file in hand, generate keys for each node. - -```bash -nebula-cert sign -name "lighthouse" -ip "192.168.100.1/24" -nebula-cert sign -name "laptop" -ip "192.168.100.2/24" -``` - -Repeate this process for each node. It is important that each is issued a unique internal ip. The IPs are specified in CIDR notation [^2]. This internal ip will be used to configure Nebula later. - -#### 4. Copy the configuration files to each host - -Each host requires the `host.key`, `host.crt`, and `ca.crt` files to be present on the system. By convention, these are located in the `/etc/nebula` directory. Make sure to copy them into this directory. - -For example, to copy the credentials to a lighthouse with ip `203.0.113.11` as `user` you may use sftp and ssh as follows: - -```bash -sftp user@203.0.113.11 </etc/apt/sources.list.d/99-tmp-nebula-overrides.list </etc/apt/preferences.d/99-tmp-nebula-prefer-stable < { config.module.rules.push({ @@ -20,9 +14,7 @@ const withMarkdownLoader = pluginFactory((config, _options) => { }, { loader: 'markdown-loader', - options: { - highlight - } + options: markedOptions } ] }); diff --git a/posts/cgit-nginx-ubuntu/main.md b/posts/cgit-nginx-ubuntu/main.md new file mode 100644 index 0000000..c225bd4 --- /dev/null +++ b/posts/cgit-nginx-ubuntu/main.md @@ -0,0 +1,96 @@ +Installing cGit behind NGINX on Ubuntu +====================================== + +[cGit](https://git.zx2c4.com/cgit/about/) is a fast web interface based on the CGI specification. It is lightweight and doesn't require a database or web authentication system. + +It's easy to configure. For some reason, all the online guides for Ubuntu decided they needed to compile it from scratch and write their own start scripts in a mix of perl and bash. You don't need superhero sysadmin skills from the late 90s. All components are packaged with systemd units... there is a better way... + +### 1. Install `cgit` and `fcgiwrap`. + +`fcgiwrap` will create a socket NGINX can use to pass the CGI variables to cGit: +``` +sudo apt install fcgiwrap +sudo apt install cgit +``` + +### 2. Modify the `cgitrc` file under `/etc/cgitrc` to your liking: +``` +# See cgitrc(5) +# prepend this string to every url +virtual-root=/ +enable-index-links=1 +enable-commit-graph=1 + +root-title=My Git Repos +root-desc=I exclusivly write code in Smalltalk-71 +logo=/assets/my_custom_logo.png + +# Add site-specific configuration +# ... + +``` + +### 3. Optionally create an assets directory and add your custom logo / css: +``` +mkdir /var/www/html/assets +cp my_custom_logo.png /var/www/html/assets +``` + +### 4. Configure NGINX + +Add the site to NGINX. This launches the `cgit.cgi` executable passing it to the `fcgiwrap` socket: +```conf +echo >/etc/nginx/sites-available/cgit.conf < **Created:** 2021-07-18 **Last Updated:** 2021-07-19 + +I am close to concluding a multi-week endevor to package [Nebula](https://github.com/slackhq/nebula), a VPN-style network mesh networking overlay. If all goes well, it will be uploaded to `debian/experimental` within the next few days. This would also mean the package would be pulled into Ubuntu during the next merge window. + +### Timeline + +Unfortunately, Debian does not adhere to a constant release cycle. This means the timeline is uncertain. It will likely be uploaded to `experimental` within a few days. [See the new queue.](https://ftp-master.debian.org/new.html) It will stay in experimental for the next three months or so until the next release occurs. (It is incompatible with the version of protobuf in unstable. This prevents it from moving into unstable until the next version release.) +``` +{upload queue} -> [experimental] -> [unstable (sid)] -> [testing] -> [next release] +``` + +Preemptively, I'm going to write up a set of install instructions specific to debian derivatives and briefly a few of the decisions made during the packaging process. + +Installation +------------ + +**Step one will currently fail. See [installing from experimental](#installing-from-experimental)** + +For the sake of simplicity, I'm going to assume that you're setting up a network with two nodes -- one lighthouse node and a node on your laptop. Once you understand the process, it easily scales to as many nodes as you wish. Pick your favorite virtualization provider in order to set up the lighthouse. The lighthouse requires minimal resources because it functions as a mutually-reachable node which synchronizes the address mappings. You could use a home server provided that you have a static ip (unlikely) or setup dynamic DNS. The latter may introduce some instability. I'm also assuming both clients are debian derivatives and have access to `apt`. + +If this is not the case, please consult the [upstream instructions](https://github.com/slackhq/nebula#user-content-getting-started-quickly) which will guide you through the processing of installing the binaries directly. + +#### 1. Install Nebula through Aptitude + +You'll need to install Nebula on both endpoints. + +```bash +sudo apt install nebula +``` + +#### 2. Creating a certificate authority + +The certificate authority is to "root of trust" for a Nebula network. Compromising the certificate authority's key file would compromise the integrity and security of the entire network. The upstream instructions recommend that you store the key file in a location with strong encryption [^1]. + +You can generate a `ca.key` and `ca.cert` file with the following command: +```bash +nebula-cert ca -name "Myorganization, Inc" +``` + +You will copy the `ca.crt` file to all the hosts. The `ca.key` file should remain secret. + +#### 4. Nebula host keys and certificates generated from that certificate authority + +With your `ca.key` file in hand, generate keys for each node. + +```bash +nebula-cert sign -name "lighthouse" -ip "192.168.100.1/24" +nebula-cert sign -name "laptop" -ip "192.168.100.2/24" +``` + +Repeate this process for each node. It is important that each is issued a unique internal ip. The IPs are specified in CIDR notation [^2]. This internal ip will be used to configure Nebula later. + +#### 4. Copy the configuration files to each host + +Each host requires the `host.key`, `host.crt`, and `ca.crt` files to be present on the system. By convention, these are located in the `/etc/nebula` directory. Make sure to copy them into this directory. + +For example, to copy the credentials to a lighthouse with ip `203.0.113.11` as `user` you may use sftp and ssh as follows: + +```bash +sftp user@203.0.113.11 </etc/apt/sources.list.d/99-tmp-nebula-overrides.list </etc/apt/preferences.d/99-tmp-nebula-prefer-stable < { return JSON.parse(postMetadata) as PostMetadata; } -async function getPosts() : Promise { - const postsDirectory = path.join(process.cwd(), 'posts'); - const directories = await fs.readdir(postsDirectory); +const POST_PATH = path.join(process.cwd(), 'posts'); + +async function getPostFromDirectory(directory : string) { + const postPath = path.join(POST_PATH, directory); + + const meta = await getMetadata(postPath); - const posts = directories.map(async (directory) => { - const postPath = path.join(postsDirectory, directory); - - const meta = await getMetadata(postPath); + return { + directory, + path: postPath, + meta + }; +} + +async function getPosts() : Promise { + const directories = await fs.readdir(POST_PATH); - return { - directory, - path: postPath, - meta - }; - }); + const posts = directories.map(getPostFromDirectory); return await Promise.all(posts); } @@ -48,10 +55,13 @@ async function getMarkdown(post : Post) : Promise { const markdown = await fs.readFile(markdownPath, 'utf8'); - return markdown; + const html = marked(markdown); + + return html; } export { getPosts, - getMetadata, + getMarkdown, + getPostFromDirectory }; \ No newline at end of file diff --git a/utils/markedOptions.js b/utils/markedOptions.js new file mode 100644 index 0000000..ebc7a6f --- /dev/null +++ b/utils/markedOptions.js @@ -0,0 +1,12 @@ +const hljs = require('highlight.js'); + +function highlight(code, lang) { + const language = hljs.getLanguage(lang) ? lang : 'plaintext'; + + const highlighted = hljs.highlight(code, { language }).value; + return highlighted; +} + +module.exports = { + highlight +}; \ No newline at end of file -- cgit v1.2.3