docs/packages/lix-docs/default.nix

131 lines
4.7 KiB
Nix
Raw Normal View History

2024-07-21 05:06:27 +00:00
{
lix-docs,
stdenv,
vim,
perl,
...
}:
let
f = "find . -type f -exec";
s = "${f} sed -i";
in
stdenv.mkDerivation {
inherit (lix-docs) pname version;
src = lix-docs.src;
nativeBuildInputs = [
vim
perl
];
installPhase = ''
defaultFix() {
sed -i '1,2d' $0
sed -i '1s/ - /\n\n/' $0
sed -i '1s/^/# /' $0
sed -i '3s/\w/\u&/' $0
sed -i '3s/$/\./' $0
}
export -f defaultFix
mkdir $out
cp -r ${lix-docs.doc}/manualMD/* $out
chmod -R +w $out
pushd $out
mv introduction.md index.md
mv advanced-topics/advanced-topics.md advanced-topics/index.md
mv advanced-topics Advanced-Topics
mv architecture/architecture.md architecture/index.md
mv command-ref Command-Reference
2024-07-21 06:13:59 +00:00
sed -i 's!^- \[\(.*\)\]!# \1 !g' glossary.md
sed -i 's/^\(.*\)\({#gloss-.*}\)\(.*\)/\1\3\2/g' glossary.md
sed -i 's/ ,/,/g' glossary.md
sed -i 's/\(\S\){/\1 {/g' glossary.md
2024-07-21 05:06:27 +00:00
pushd Command-Reference
mv command-ref.md index.md
mv files.md files/index.md
mv nix-env.md nix-env/index.md
mv nix-store.md nix-store/index.md
# Fixup all Nix3(aka new cli) commands
pushd new-cli
${s} '6,7d' {} \;
${s} '6s/ - /\n\n/' {} \;
${s} '6s/^/# /' {} \;
${s} '8s/\w/\u&/' {} \;
${s} '8s/$/\./' {} \;
${f} ex -c '1,5m9' -c w -c q {} \;
popd
mv new-cli New-CLI
# Fixup all non-nix3 commands
find . -type f -name "nix-*.md" -exec bash -c 'defaultFix "$0"' {} \;
# Fixup nix-store
pushd nix-store
find . -type f -name "*.md" -exec bash -c 'defaultFix "$0"' {} \;
sed -i 's!\./nix-store!\./!g' index.md
popd
# Fixup Nix-env
pushd nix-env
find . -type f -name "*.md" -exec bash -c 'defaultFix "$0"' {} \;
sed -i 's!\./nix-env!\./!g' index.md
2024-07-21 06:13:59 +00:00
sed -i 's!../Command-Reference/!\./!g' index.md
2024-07-21 05:06:27 +00:00
popd
2024-07-21 06:13:59 +00:00
bash -c defaultFix conf-file.md
2024-07-21 05:06:27 +00:00
popd
# Contributing directory
pushd contributing
mv contributing.md index.md
ex -c '1,9m11' -c w -c q experimental-features.md
sed -i 's!^## \[\(.*\)\]!## \1 !g' experimental-features.md
popd
2024-07-21 06:13:59 +00:00
pushd language
sed -i '3s/##/#/' values.md
sed -E -i 's/(.*)(#type-\w+)">(\w+)<\/a>/## \3 {\2}/' values.md
sed -i 's/## List/# List/' values.md
sed -i 's/## Attribute Set/# Attribute Set/' values.md
popd
2024-07-21 05:06:27 +00:00
# Final directories
mv installation/installation.md installation/index.md
mv package-management/package-management.md package-management/index.md
mv package-management Package-Management
mv protocols/protocols.md protocols/index.md
mv release-notes/release-notes.md release-notes/index.md
# Admonitions
2024-07-21 06:13:59 +00:00
find . -type f -name "*.md" -exec perl -pi -e 's/\s*<div class="warning">/!!! warning/g' {} \;
2024-07-21 05:06:27 +00:00
find . -type f -name "*.md" -exec sed -i '/<\/div>/d' {} \;
find . -type f -name "*.md" -exec perl -pi -e 's/\n\n\n/placeholderstring123/g' -0 {} \;
find . -type f -name "*.md" -exec sed -i '/^!!! warning/,/placeholderstring123/s/^/\ \ \ \ /' {} \;
find . -type f -name "*.md" -exec perl -pi -e 's/placeholderstring123/\n\n\n/g' -0 {} \;
2024-07-21 06:13:59 +00:00
find . -type f -name "*.md" -exec perl -pi -e 's/\s*> \*\*Warning\*\*/!!! warning2/g' {} \;
2024-07-21 05:06:27 +00:00
find . -type f -name "*.md" -exec sed -i '/^!!! warning2/,/^$/s/ >/\ \ \ /' {} \;
find . -type f -name "*.md" -exec sed -i 's/!!! warning2/!!! warning/' {} \;
find . -type f -name "*.md" -exec sed -i 's/^\ \ \ \ !!! warning/!!! warning/' {} \;
find . -type f -name "*.md" -exec perl -pi -e 's/!!! warning\n \n/!!! warning\n/g' -0 {} \;
2024-07-21 06:13:59 +00:00
find . -type f -name "*.md" -exec perl -pi -e 's/\s*> \*\*Note\*\*\n.*/\n\n!!! note/g' -0 {} \;
find . -type f -name "*.md" -exec sed -i '/^!!! note/,/^[^!>]/s/^>/\ \ \ /' {} \;
2024-07-21 05:06:27 +00:00
# Increase all headings past line 1 by one level
# Lix docs all have level-1 headings, we need at least level 2
find . -type f -name "*.md" -exec sed -i '2,$s/# [^#]*/#&/g' {} \;
# Clean up some local links
2024-07-21 06:13:59 +00:00
find . -type f -name "*.md" -exec sed -i 's/advanced-topics/Advanced-Topics/g' {} \;
2024-07-21 05:06:27 +00:00
find . -type f -name "*.md" -exec sed -i 's/command-ref/Command-Reference/g' {} \;
2024-07-21 06:13:59 +00:00
find . -type f -name "*.md" -exec sed -i 's/package-management/Package-Management/g' {} \;
2024-07-21 05:06:27 +00:00
find . -type f -name "*.md" -exec sed -i 's/new-cli/New-CLI/g' {} \;
2024-07-21 06:13:59 +00:00
find . -type f -name "*.md" -exec sed -i 's/Command-Reference\.html//g' {} \;
find . -type f -name "*.md" -exec sed -i 's/Command-Reference\.md//g' {} \;
find . -type f -name "*.md" -exec sed -i 's/conf-file\.html/conf-file\.md/g' {} \;
find . -type f -name "*.md" -exec sed -i 's/nix-env\.md/nix-env/g' {} \;
find . -type f -name "*.md" -exec sed -i 's/values\.html/values\.md/g' {} \;
# Final misc cleanups
find . -type f -name "*.md" -exec sed -i 's/[\]//g' {} \;
2024-07-21 05:06:27 +00:00
'';
}