build a hugo docs page from the readme files
This commit is contained in:
parent
bfe941217d
commit
d106386cc0
5 changed files with 229 additions and 3 deletions
118
docs/build-docs.sh
Executable file
118
docs/build-docs.sh
Executable file
|
|
@ -0,0 +1,118 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Script to collect README files and prepare them for Hugo
|
||||
# This script is called during the Nix build process
|
||||
|
||||
REPO_ROOT="${1:-.}"
|
||||
CONTENT_DIR="${2:-content}"
|
||||
|
||||
echo "Building documentation from $REPO_ROOT to $CONTENT_DIR"
|
||||
|
||||
mkdir -p "$CONTENT_DIR"
|
||||
mkdir -p "$CONTENT_DIR/hosts"
|
||||
|
||||
# Function to convert relative links to work in Hugo
|
||||
# Converts markdown links like [text](../other/README.md) to [text](/other/)
|
||||
fix_links() {
|
||||
local file="$1"
|
||||
local base_path="$2"
|
||||
|
||||
sed -E \
|
||||
-e 's|\[([^\]]+)\]\((\.\./)+hosts/([^/]+)/README\.md\)|\[\1\](/hosts/\3/)|g' \
|
||||
-e 's|\[([^\]]+)\]\(\.\./([^/]+)/README\.md\)|\[\1\](/hosts/\2/)|g' \
|
||||
-e 's|\[([^\]]+)\]\(\.\./(README\.md)\)|\[\1\](/)|g' \
|
||||
-e 's|\[([^\]]+)\]\(\.\./\.\./README\.md\)|\[\1\](/)|g' \
|
||||
-e 's|\[([^\]]+)\]\(\./([^/]+)/README\.md\)|\[\1\](/\2/)|g' \
|
||||
-e 's|\[hosts/([^/]+)/README\.md\]\(hosts/\1/README\.md\)|\[hosts/\1/\]\(/hosts/\1/\)|g' \
|
||||
-e 's|\[([^\]]+)\]\(hosts/([^/]+)/README\.md\)|\[\1\](/hosts/\2/)|g' \
|
||||
-e 's|\[([^\]]+)\]\(README\.md\)|\[\1\](/)|g' \
|
||||
"$file"
|
||||
}
|
||||
|
||||
# Process main README.md
|
||||
if [ -f "$REPO_ROOT/README.md" ]; then
|
||||
echo "Processing main README.md..."
|
||||
{
|
||||
cat <<'EOF'
|
||||
---
|
||||
title: "StuRa HTW Infrastructure"
|
||||
date: 2024-01-01
|
||||
weight: 1
|
||||
---
|
||||
|
||||
EOF
|
||||
fix_links "$REPO_ROOT/README.md" "/"
|
||||
} > "$CONTENT_DIR/_index.md"
|
||||
fi
|
||||
|
||||
# Process CLAUDE.md as a separate page
|
||||
if [ -f "$REPO_ROOT/CLAUDE.md" ]; then
|
||||
echo "Processing CLAUDE.md..."
|
||||
{
|
||||
cat <<'EOF'
|
||||
---
|
||||
title: "Claude Code Guide"
|
||||
date: 2024-01-01
|
||||
weight: 10
|
||||
---
|
||||
|
||||
EOF
|
||||
fix_links "$REPO_ROOT/CLAUDE.md" "/"
|
||||
} > "$CONTENT_DIR/claude-guide.md"
|
||||
fi
|
||||
|
||||
# Create hosts index page
|
||||
cat > "$CONTENT_DIR/hosts/_index.md" <<'EOF'
|
||||
---
|
||||
title: "Hosts"
|
||||
date: 2024-01-01
|
||||
weight: 2
|
||||
---
|
||||
|
||||
# Host Configurations
|
||||
|
||||
This section contains documentation for each host in the infrastructure.
|
||||
EOF
|
||||
|
||||
# Process host README files
|
||||
if [ -d "$REPO_ROOT/hosts" ]; then
|
||||
for host_dir in "$REPO_ROOT/hosts"/*; do
|
||||
if [ -d "$host_dir" ]; then
|
||||
host_name=$(basename "$host_dir")
|
||||
readme="$host_dir/README.md"
|
||||
|
||||
if [ -f "$readme" ]; then
|
||||
echo "Processing host: $host_name"
|
||||
{
|
||||
cat <<EOF
|
||||
---
|
||||
title: "$host_name"
|
||||
date: 2024-01-01
|
||||
---
|
||||
|
||||
EOF
|
||||
fix_links "$readme" "/hosts/$host_name"
|
||||
} > "$CONTENT_DIR/hosts/$host_name.md"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Process keys README if it exists
|
||||
if [ -f "$REPO_ROOT/keys/README.md" ]; then
|
||||
echo "Processing keys/README.md..."
|
||||
{
|
||||
cat <<'EOF'
|
||||
---
|
||||
title: "Key Management"
|
||||
date: 2024-01-01
|
||||
weight: 5
|
||||
---
|
||||
|
||||
EOF
|
||||
fix_links "$REPO_ROOT/keys/README.md" "/keys"
|
||||
} > "$CONTENT_DIR/keys.md"
|
||||
fi
|
||||
|
||||
echo "Documentation build complete!"
|
||||
20
docs/hugo.yaml
Normal file
20
docs/hugo.yaml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
baseURL: 'https://docs.adm.htw.stura-dresden.de/'
|
||||
languageCode: en-us
|
||||
title: StuRa HTW Infrastructure Documentation
|
||||
theme: hugo-book
|
||||
|
||||
params:
|
||||
BookTheme: auto
|
||||
BookToC: true
|
||||
BookRepo: https://codeberg.org/stura-htw-dresden/stura-infra
|
||||
BookEditPath: edit/master
|
||||
BookSearch: true
|
||||
BookComments: false
|
||||
BookPortableLinks: true
|
||||
BookMenuBundle: true
|
||||
|
||||
menu:
|
||||
after:
|
||||
- name: Repository
|
||||
url: https://codeberg.org/stura-htw-dresden/stura-infra
|
||||
weight: 10
|
||||
BIN
flake-show.png
BIN
flake-show.png
Binary file not shown.
|
Before Width: | Height: | Size: 125 KiB |
44
flake.nix
44
flake.nix
|
|
@ -77,6 +77,46 @@
|
|||
];
|
||||
};
|
||||
packages.x86_64-linux =
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||
|
||||
# Hugo documentation site package
|
||||
docs-site = pkgs.stdenv.mkDerivation {
|
||||
name = "stura-infra-docs";
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = [ pkgs.hugo ];
|
||||
|
||||
buildPhase = ''
|
||||
# Create Hugo structure
|
||||
mkdir -p hugo-site
|
||||
cp ${./docs/hugo.yaml} hugo-site/hugo.yaml
|
||||
|
||||
# Install hugo-book theme
|
||||
mkdir -p hugo-site/themes
|
||||
cp -r ${
|
||||
pkgs.fetchFromGitHub {
|
||||
owner = "alex-shpak";
|
||||
repo = "hugo-book";
|
||||
rev = "v13";
|
||||
sha256 = "sha256-r2KfmWK7BC7LjnZVvwb2Mbqnd8a6Q32fBqiQfZTpGy4=";
|
||||
}
|
||||
} hugo-site/themes/hugo-book
|
||||
|
||||
# Build content from README files
|
||||
bash ${./docs/build-docs.sh} . hugo-site/content
|
||||
|
||||
# Build Hugo site
|
||||
cd hugo-site
|
||||
hugo --minify
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out
|
||||
cp -r public/* $out/
|
||||
'';
|
||||
};
|
||||
in
|
||||
builtins.foldl'
|
||||
(
|
||||
result: name:
|
||||
|
|
@ -84,7 +124,7 @@
|
|||
// {
|
||||
# run nixos-rebuild switch on the target system
|
||||
# the config will be built locally and copied over
|
||||
"${name}-update" = nixpkgs.legacyPackages.x86_64-linux.writeShellScriptBin "update" ''
|
||||
"${name}-update" = pkgs.writeShellScriptBin "update" ''
|
||||
nixos-rebuild switch --flake .#${name} --target-host root@${
|
||||
(builtins.head (
|
||||
nixosConfigurations.${name}.config.networking.interfaces.${
|
||||
|
|
@ -95,7 +135,7 @@
|
|||
'';
|
||||
}
|
||||
)
|
||||
{ }
|
||||
{ inherit docs-site; }
|
||||
(
|
||||
# filter all nixos configs containing installer
|
||||
builtins.filter (item: !nixpkgs.lib.hasInfix "-" item) (builtins.attrNames nixosConfigurations)
|
||||
|
|
|
|||
|
|
@ -41,8 +41,17 @@
|
|||
# wenn instanzen in die flake migriert sind könnte man das autogenerierien
|
||||
services =
|
||||
let
|
||||
# Documentation site from flake package
|
||||
docsSite = self.packages.x86_64-linux.docs-site;
|
||||
|
||||
# jeder Block beschreibt eine Weiterleitung von port 80 und 443 für einen fqdn
|
||||
forwards = {
|
||||
docs = {
|
||||
dest = "127.0.0.1";
|
||||
domain = "docs.adm.htw.stura-dresden.de";
|
||||
httpPort = 8080;
|
||||
httpsPort = 8443;
|
||||
};
|
||||
plone = {
|
||||
dest = "141.56.51.3";
|
||||
domain = "stura.htw-dresden.de";
|
||||
|
|
@ -206,6 +215,44 @@
|
|||
}
|
||||
];
|
||||
};
|
||||
|
||||
# Nginx to serve the documentation site
|
||||
nginx = {
|
||||
enable = true;
|
||||
virtualHosts."docs.adm.htw.stura-dresden.de" = {
|
||||
enableACME = true;
|
||||
listen = [
|
||||
{
|
||||
addr = "127.0.0.1";
|
||||
port = 8080;
|
||||
}
|
||||
];
|
||||
locations."/" = {
|
||||
root = docsSite;
|
||||
tryFiles = "$uri $uri/ $uri.html =404";
|
||||
};
|
||||
};
|
||||
|
||||
# HTTPS version for internal serving
|
||||
appendHttpConfig = ''
|
||||
server {
|
||||
listen 127.0.0.1:8443 ssl http2;
|
||||
server_name docs.adm.htw.stura-dresden.de;
|
||||
|
||||
ssl_certificate ${config.security.acme.certs."docs.adm.htw.stura-dresden.de".directory}/cert.pem;
|
||||
ssl_certificate_key ${
|
||||
config.security.acme.certs."docs.adm.htw.stura-dresden.de".directory
|
||||
}/key.pem;
|
||||
|
||||
location / {
|
||||
root ${docsSite};
|
||||
try_files $uri $uri/ $uri.html =404;
|
||||
}
|
||||
}
|
||||
'';
|
||||
};
|
||||
|
||||
# ACME certificate for docs site
|
||||
haproxy = {
|
||||
enable = true;
|
||||
config = ''
|
||||
|
|
@ -242,7 +289,8 @@
|
|||
# hier wird eine regel pro domain aus der forwarder liste generiert
|
||||
${lib.foldlAttrs (
|
||||
prev: name: value:
|
||||
prev + ''
|
||||
prev
|
||||
+ ''
|
||||
acl is_${name} hdr(host) -i ${value.domain}
|
||||
''
|
||||
) "" forwards}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue