docs: link to all "available" versions of the docs

This commit is contained in:
Matt Sturgeon 2024-11-20 19:47:27 +00:00
parent b08470b31d
commit 07f23a60fd
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
3 changed files with 106 additions and 14 deletions

View file

@ -50,23 +50,54 @@ jobs:
run: | run: |
set -ex set -ex
# 1: branch # A list of all doc versions to be built,
# 2: install dir (relative to /nixvim/) # (Written to versions.json)
build() { echo '
branch="$1" [
dir="${2:+/$2}" {
flakeref="github:${repo}${branch:+/$branch}" "branch": "main",
baseHref="/${repoName}${dir}/" "nixpkgsBranch": "nixos-unstable"
installDir="${out}${dir}" },
{
"branch": "nixos-24.05",
"nixpkgsBranch": "nixos-24.05",
"subPath": "stable"
// TODO: consider having 24.05 instead of stable?
}
]
' | sed 's/^ *\/\/.*//' | jq \
--arg repoName "$repoName" \
'map(
.
# Ensure subPath is a string
| .subPath = (.subPath // "")
# Construct baseHref from $repoName and .subPath
| .baseHref = (
.subPath
| if . == "" then "" else "/\(.)" end
| $repoName + .
| "/\(.)/"
)
)' > versions.json
# Build docs for the given flake ref, overriding baseHref in the derivation args # 1: branch
# 2: baseHref
# 3: install dir
build() {
flakeref="github:${repo}${1:+/$1}"
baseHref="$2"
installDir="${out}${3:+/$3}"
# Build docs for the given flake ref, overriding the relevant derivation args
nix build --impure \ nix build --impure \
--argstr flakeref "$flakeref" \ --argstr flakeref "$flakeref" \
--argstr baseHref "$baseHref" \ --argstr baseHref "$baseHref" \
--arg-from-file versionsJson versions.json \
--expr ' --expr '
{ {
flakeref, flakeref,
baseHref, baseHref,
versionsJson,
system ? builtins.currentSystem, system ? builtins.currentSystem,
}: }:
let let
@ -75,6 +106,7 @@ jobs:
in in
packages.docs.override { packages.docs.override {
inherit baseHref; inherit baseHref;
availableVersions = builtins.fromJSON versionsJson;
} }
' '
@ -83,12 +115,16 @@ jobs:
cp -r result/share/doc/* "$installDir" cp -r result/share/doc/* "$installDir"
} }
# Install main-branch docs at the top-level # For each version of the docs...
build 'main' '' jq -c '.[]' versions.json |
while IFS=$"\n" read -r entry; do
branch=$(echo "$entry" | jq -r '.branch')
baseHref=$(echo "$entry" | jq -r '.baseHref')
installDir=$(echo "$entry" | jq -r '.subPath')
# Install 24.05 docs under 'stable' # Build this version of the docs
# TODO: consider having `<release>` instead of `stable` build "$branch" "$baseHref" "$installDir"
build 'nixos-24.05' 'stable' done
- name: Upload artifact - name: Upload artifact
uses: actions/upload-pages-artifact@v3 uses: actions/upload-pages-artifact@v3

View file

@ -1,5 +1,6 @@
{ {
pkgs, pkgs,
runCommand,
lib, lib,
modules, modules,
helpers, helpers,
@ -8,6 +9,9 @@
hmOptions, hmOptions,
# The root directory of the site # The root directory of the site
baseHref ? "/", baseHref ? "/",
# A list of all available docs that should be linked to
# Each element should contain { branch; nixpkgsBranch; baseHref; }
availableVersions ? [ ],
}: }:
with lib; with lib;
let let
@ -229,6 +233,46 @@ let
) docs.modules; ) docs.modules;
}; };
# Zip the list of attrs into an attr of lists, for use as bash arrays
zippedVersions =
assert lib.assertMsg
(lib.all (o: o ? branch && o ? nixpkgsBranch && o ? baseHref) availableVersions)
''
Expected all "availableVersions" docs entries to contain { branch, nixpkgsBranch, baseHref } attrs!
'';
lib.zipAttrs availableVersions;
docs-versions =
runCommand "docs-versions"
{
__structuredAttrs = true;
branches = zippedVersions.branch or [ ];
nixpkgsBranches = zippedVersions.nixpkgsBranch or [ ];
baseHrefs = zippedVersions.baseHref or [ ];
current = baseHref;
}
''
touch "$out"
for i in ''${!branches[@]}; do
branch="''${branches[i]}"
nixpkgs="''${nixpkgsBranches[i]}"
baseHref="''${baseHrefs[i]}"
linkText="\`$branch\` branch"
link=
suffix=
if [ "$baseHref" = "$current" ]; then
# Don't bother linking to ourselves
link="$linkText"
suffix=" _(this page)_"
else
link="[$linkText]($baseHref)"
fi
echo "- The $link, for use with nixpkgs \`$nixpkgs\`$suffix" >> "$out"
done
'';
prepareMD = '' prepareMD = ''
# Copy inputs into the build directory # Copy inputs into the build directory
cp -r --no-preserve=all $inputs/* ./ cp -r --no-preserve=all $inputs/* ./
@ -249,6 +293,10 @@ let
substituteInPlace ./SUMMARY.md \ substituteInPlace ./SUMMARY.md \
--replace-fail "@NIXVIM_OPTIONS@" "$(cat ${pkgs.writeText "nixvim-options-summary.md" mdbook.nixvimOptions})" --replace-fail "@NIXVIM_OPTIONS@" "$(cat ${pkgs.writeText "nixvim-options-summary.md" mdbook.nixvimOptions})"
# Patch index.md
substituteInPlace ./index.md \
--replace-fail "@DOCS_VERSIONS@" "$(cat ${docs-versions})"
substituteInPlace ./modules/hm.md \ substituteInPlace ./modules/hm.md \
--replace-fail "@HM_OPTIONS@" "$(cat ${mkMDDoc hmOptions})" --replace-fail "@HM_OPTIONS@" "$(cat ${mkMDDoc hmOptions})"
''; '';

View file

@ -1,5 +1,13 @@
# NixVim - A Neovim configuration system for nix # NixVim - A Neovim configuration system for nix
## Other versions of these docs
Please ensure you are referencing documentation that corresponds to the Nixvim version you are using!
Documentation is currently available for the following versions:
@DOCS_VERSIONS@
## What is it? ## What is it?
NixVim is a [Neovim](https://neovim.io) distribution built around NixVim is a [Neovim](https://neovim.io) distribution built around
[Nix](https://nixos.org) modules. It is distributed as a Nix flake, and [Nix](https://nixos.org) modules. It is distributed as a Nix flake, and