mirror of
https://github.com/Mic92/nixos-wiki-infra.git
synced 2025-06-26 12:41:34 +02:00
Merge pull request #263 from NixOS/wiki-pages
allow to add wiki pages from the repository
This commit is contained in:
commit
d943967a05
@ -25,7 +25,16 @@
|
||||
emergencyContact = "nixos-wiki@thalheim.io";
|
||||
passwordSender = "nixos-wiki@thalheim.io";
|
||||
noReplyAddress = "nixos-wiki-no-reply@thalheim.io";
|
||||
pages = {
|
||||
pageConfig = {
|
||||
"wiki-sync-test-page.wiki" = {
|
||||
title = "Wiki Sync Test Page";
|
||||
namespace = "";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
services.nginx.virtualHosts.${config.services.mediawiki.nginx.hostName} = {
|
||||
enableACME = false;
|
||||
forceSSL = false;
|
||||
@ -36,11 +45,21 @@
|
||||
testScript = ''
|
||||
start_all()
|
||||
|
||||
machine.wait_for_unit("phpfpm-mediawiki.service")
|
||||
machine.wait_for_unit("nginx.service")
|
||||
machine.wait_for_unit("mediawiki-init.service")
|
||||
wiki.wait_for_unit("phpfpm-mediawiki.service")
|
||||
wiki.wait_for_unit("nginx.service")
|
||||
wiki.wait_for_unit("mediawiki-init.service")
|
||||
|
||||
page = machine.succeed("curl -vL http://nixos-wiki.example.com/")
|
||||
page = wiki.succeed("curl -vL http://nixos-wiki.example.com/")
|
||||
assert "MediaWiki has been installed" in page
|
||||
|
||||
# Test wiki pages sync functionality
|
||||
print("Testing wiki pages sync...")
|
||||
|
||||
# Check that the test page was created on the wiki
|
||||
print("Checking if test page was created...")
|
||||
test_page = wiki.succeed("curl -s http://nixos-wiki.example.com/wiki/Wiki_Sync_Test_Page")
|
||||
|
||||
# Check for title in HTML
|
||||
assert "Automatic synchronization from git repository" in test_page, f"Expected title not found in test page: {test_page}"
|
||||
'';
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ let
|
||||
cfg = config.services.nixos-wiki;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./pages.nix
|
||||
];
|
||||
options = {
|
||||
services.nixos-wiki = {
|
||||
hostname = lib.mkOption {
|
||||
|
120
modules/nixos-wiki/pages.nix
Normal file
120
modules/nixos-wiki/pages.nix
Normal file
@ -0,0 +1,120 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.nixos-wiki.pages;
|
||||
|
||||
# Path to pages directory
|
||||
pagesDir = lib.fileset.toSource {
|
||||
root = ../../.;
|
||||
fileset = lib.fileset.fileFilter (file: file.hasExt "wiki") ../../pages;
|
||||
};
|
||||
|
||||
pageType = types.submodule {
|
||||
options = {
|
||||
title = mkOption {
|
||||
type = types.str;
|
||||
description = "Wiki page title";
|
||||
};
|
||||
namespace = mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = "Wiki namespace (empty for main namespace)";
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.services.nixos-wiki.pages = {
|
||||
|
||||
pageConfig = mkOption {
|
||||
type = types.attrsOf pageType;
|
||||
default = { };
|
||||
description = "Configuration for wiki pages, keyed by filename";
|
||||
example = {
|
||||
"main-page.wiki" = {
|
||||
title = "Main Page";
|
||||
namespace = "";
|
||||
};
|
||||
"help-editing.wiki" = {
|
||||
title = "Editing";
|
||||
namespace = "Help";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf (cfg.pageConfig != { }) {
|
||||
|
||||
systemd.services.wiki-pages-sync = {
|
||||
description = "Synchronize wiki pages from git repository";
|
||||
after = [ "mediawiki-init.service" ];
|
||||
requiredBy = [ "multi-user.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "mediawiki";
|
||||
Group = "nginx";
|
||||
};
|
||||
environment = config.services.phpfpm.pools.mediawiki.phpEnv;
|
||||
script = ''
|
||||
# Read the JSON config
|
||||
config='${builtins.toJSON cfg.pageConfig}'
|
||||
|
||||
# Process each .wiki file (they're in the pages subdirectory)
|
||||
for wiki_file in "${pagesDir}"/pages/*.wiki; do
|
||||
# Skip if no .wiki files found
|
||||
[ -e "$wiki_file" ] || continue
|
||||
|
||||
filename=$(basename "$wiki_file")
|
||||
|
||||
# Extract configuration for this file from JSON
|
||||
title=$(echo "$config" | ${pkgs.jq}/bin/jq -r --arg file "$filename" '.[$file].title // empty')
|
||||
namespace=$(echo "$config" | ${pkgs.jq}/bin/jq -r --arg file "$filename" '.[$file].namespace // ""')
|
||||
|
||||
# Skip if no config found for this file
|
||||
if [ -z "$title" ]; then
|
||||
echo "Warning: No configuration found for $filename, skipping"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Construct full page title
|
||||
if [ -n "$namespace" ]; then
|
||||
full_title="$namespace:$title"
|
||||
else
|
||||
full_title="$title"
|
||||
fi
|
||||
|
||||
echo "Processing: $filename -> $full_title"
|
||||
|
||||
# Read page content and add management comment
|
||||
content=$(cat "$wiki_file")
|
||||
content_with_comment="<!--
|
||||
This page is automatically managed through git repository synchronization.
|
||||
Do not edit this page directly on the wiki - changes will be overwritten.
|
||||
To edit this page, modify the file: $filename
|
||||
Source: https://github.com/NixOS/nixos-wiki-infra/blob/main/pages/$filename
|
||||
-->
|
||||
|
||||
$content"
|
||||
|
||||
# Edit the page using maintenance script (no --user means system maintenance user)
|
||||
echo "$content_with_comment" | ${config.services.phpfpm.pools.mediawiki.phpPackage}/bin/php \
|
||||
${config.services.mediawiki.finalPackage}/share/mediawiki/maintenance/run.php edit \
|
||||
--summary="Updated $filename from git repository" \
|
||||
--bot \
|
||||
"$full_title"
|
||||
|
||||
echo "Successfully updated: $full_title"
|
||||
done
|
||||
|
||||
echo "Wiki synchronization completed successfully"
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
16
pages/wiki-sync-test-page.wiki
Normal file
16
pages/wiki-sync-test-page.wiki
Normal file
@ -0,0 +1,16 @@
|
||||
{{DISPLAYTITLE:Wiki Sync Test Page}}
|
||||
This is a '''test page''' for the git-to-wiki synchronization system.
|
||||
|
||||
== Features ==
|
||||
|
||||
* Automatic synchronization from git repository
|
||||
* Page protection management
|
||||
* MediaWiki markup support
|
||||
|
||||
== Test Content ==
|
||||
|
||||
This page is managed through the git repository and automatically deployed to the wiki.
|
||||
|
||||
Changes made to this file in the repository will be reflected on the wiki after deployment.
|
||||
|
||||
[[Category:Test]]
|
Loading…
x
Reference in New Issue
Block a user