Merge pull request 'automatically include docs from clan-core' (#41) from DavHau-main into main
This commit is contained in:
commit
9387abe8ce
15
README.md
15
README.md
@ -5,15 +5,22 @@ We use [zola](https://www.getzola.org/) for building a static website.
|
|||||||
|
|
||||||
## Build the homepage
|
## Build the homepage
|
||||||
|
|
||||||
```
|
This will build the website including pages defined in the clan-core repo under `/docs`:
|
||||||
$ zola build
|
|
||||||
|
```command
|
||||||
|
$ nix build
|
||||||
```
|
```
|
||||||
|
|
||||||
## Start a local webserver
|
## Start a local webserver
|
||||||
|
|
||||||
|
This server will include all the pages from clan-core, but doesn't automatically refresh. Also make sure to wipe your browsers cache after each change.
|
||||||
|
|
||||||
|
```command
|
||||||
|
$ nix run .#serve
|
||||||
```
|
```
|
||||||
$ zola serve
|
|
||||||
```
|
## zola build & serve
|
||||||
|
Alternatively `zola build` and `zola serve` can be used for development but the result will be missing the pages defined in the clan-core repo.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
67
flake-parts/website.nix
Normal file
67
flake-parts/website.nix
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
{
|
||||||
|
self,
|
||||||
|
inputs,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
perSystem = {
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
self',
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
build = baseUrl: pkgs.runCommand "website" {
|
||||||
|
buildInputs = [ pkgs.zola ];
|
||||||
|
} ''
|
||||||
|
mkdir -p $out
|
||||||
|
cp -r ${self}/* .
|
||||||
|
chmod -R u+w .
|
||||||
|
|
||||||
|
substituteInPlace config.toml --replace \
|
||||||
|
'base_url = "https://clan.lol"' \
|
||||||
|
'base_url = "${baseUrl}"' \
|
||||||
|
|
||||||
|
# generates a zola compatible .md from a clan-core/docs/**/*.md
|
||||||
|
generatePage() {
|
||||||
|
local sourceFile="$1"
|
||||||
|
local targetFile="$2"
|
||||||
|
|
||||||
|
# generate title by reading first non-empty line of $file and stripping all '#' symbols
|
||||||
|
title=$(sed -n '/./{p;q}' "$sourceFile" | sed 's/#*//g')
|
||||||
|
echo "generating page from clan-core: $title"
|
||||||
|
|
||||||
|
# generate header with title, template, weight to make zola happy
|
||||||
|
echo -e "+++\ntitle = \"$title\"\ntemplate = \"docs/page.html\"\nweight = 0+++" > "$targetFile"
|
||||||
|
|
||||||
|
# append everything from the file but remove header line starting with '#' and all preceding non-empty lines
|
||||||
|
tail -n +2 "$sourceFile" >> "$targetFile"
|
||||||
|
}
|
||||||
|
|
||||||
|
# inject pages from clan-core
|
||||||
|
for dir in ${inputs.clan-core}/docs/*; do
|
||||||
|
subdir=$(basename $dir)
|
||||||
|
targetDir="content/docs/$subdir"
|
||||||
|
mkdir -p "$targetDir"
|
||||||
|
for file in ${inputs.clan-core}/docs/$subdir/*.md; do
|
||||||
|
target="content/docs/$subdir/$(basename $file)"
|
||||||
|
# only generate page if file doesn't start with _
|
||||||
|
if [[ $(basename $file) == _* ]]; then
|
||||||
|
cat "$file" > "$target"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
generatePage "$file" "$target"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
zola build
|
||||||
|
cp -r public/* public/.* $out
|
||||||
|
'';
|
||||||
|
in {
|
||||||
|
packages.default = self'.packages.website;
|
||||||
|
packages.website = build "https://clan.lol";
|
||||||
|
packages.website-localhost = build "http://localhost:1111";
|
||||||
|
packages.serve = pkgs.writeScriptBin "serve-local" ''
|
||||||
|
${pkgs.python3}/bin/python -m http.server 1111 \
|
||||||
|
-d ${self'.packages.website-localhost}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
@ -14,11 +14,11 @@
|
|||||||
"treefmt-nix": "treefmt-nix"
|
"treefmt-nix": "treefmt-nix"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1705080849,
|
"lastModified": 1705474551,
|
||||||
"narHash": "sha256-GdBbhCgscYWF2uK0kbU8w30V7GlOQXVm/eXgLye3gR8=",
|
"narHash": "sha256-nWBj2Ob/bxhf16BXV5gBnmDYbOSAWtZRCFUGWjtYnb4=",
|
||||||
"ref": "refs/heads/main",
|
"ref": "refs/heads/main",
|
||||||
"rev": "07a0e1db0981c0db3ca6f7cbd8a68d86b2245eff",
|
"rev": "de65c4062af43e5a976254899da2b0734c7d263a",
|
||||||
"revCount": 1779,
|
"revCount": 1789,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.clan.lol/clan/clan-core"
|
"url": "https://git.clan.lol/clan/clan-core"
|
||||||
},
|
},
|
||||||
|
17
flake.nix
17
flake.nix
@ -10,24 +10,17 @@
|
|||||||
clan-core.inputs.nixpkgs.follows = "nixpkgs";
|
clan-core.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = inputs@{ self, flake-parts, ... }:
|
outputs = inputs@{ self, flake-parts, clan-core, ... }:
|
||||||
flake-parts.lib.mkFlake { inherit inputs; } ({ lib, ... }: {
|
flake-parts.lib.mkFlake { inherit inputs; } ({ lib, ... }: {
|
||||||
systems = [ "x86_64-linux" ];
|
systems = [ "x86_64-linux" ];
|
||||||
imports = [
|
imports = [
|
||||||
./flake-parts/deploy.nix
|
./flake-parts/deploy.nix
|
||||||
./flake-parts/new-post.nix
|
|
||||||
./flake-parts/devShells
|
./flake-parts/devShells
|
||||||
|
./flake-parts/new-post.nix
|
||||||
|
./flake-parts/website.nix
|
||||||
];
|
];
|
||||||
perSystem = { pkgs, ... }: {
|
perSystem = {pkgs, ...}: {
|
||||||
packages.default = pkgs.runCommand "website" {
|
formatter = pkgs.writeShellScriptBin "true" "true";
|
||||||
buildInputs = [ pkgs.zola ];
|
|
||||||
} ''
|
|
||||||
mkdir -p $out
|
|
||||||
cp -r ${self}/* .
|
|
||||||
chmod -R u+w .
|
|
||||||
zola build
|
|
||||||
cp -r public/* public/.* $out
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user