From a7676d06b6cbebea7dc44924717c54645f0e6fb4 Mon Sep 17 00:00:00 2001 From: Leyla Becker Date: Wed, 11 Feb 2026 15:51:26 -0600 Subject: [PATCH] feat: added site map --- .gitignore | 1 + _data/site.js | 7 +++++++ eleventy.config.js | 2 ++ flake.nix | 11 +++++++++-- nix/configuration.nix | 6 +----- nix/module.nix | 37 ++++++++++++++++++++++++------------- nix/package.nix | 3 ++- post-redirects.njk | 1 + sitemap.njk | 15 +++++++++++++++ 9 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 _data/site.js create mode 100644 sitemap.njk diff --git a/.gitignore b/.gitignore index b4b4347..1c9d475 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ _site # nix packages .direnv +result # Environment variables .env diff --git a/_data/site.js b/_data/site.js new file mode 100644 index 0000000..e214bbe --- /dev/null +++ b/_data/site.js @@ -0,0 +1,7 @@ +module.exports = { + // Set SITE_URL environment variable to build for different domains: + // SITE_URL=https://blog.jan-leila.com pnpm run build + // SITE_URL=https://volpe.jan-leila.com pnpm run build + // SITE_URL=http://your-onion-address.onion pnpm run build + url: process.env.SITE_URL || "http://localhost:8080" +}; \ No newline at end of file diff --git a/eleventy.config.js b/eleventy.config.js index b8668db..f1d7345 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -223,6 +223,8 @@ module.exports = (eleventyConfig) => { eleventyConfig.addPassthroughCopy("css"); eleventyConfig.addPassthroughCopy("robots.txt"); + eleventyConfig.ignores.add("README.md"); + return { dir: { input: ".", diff --git a/flake.nix b/flake.nix index 47d9e3b..00aa531 100644 --- a/flake.nix +++ b/flake.nix @@ -20,8 +20,15 @@ }); in { packages = forEachSupportedSystem ({pkgs}: { - default = pkgs.callPackage ./nix/package.nix {}; - volpe = pkgs.callPackage ./nix/package.nix {}; + default = pkgs.callPackage ./nix/package.nix { + siteUrl = "https://blog.jan-leila.com"; + }; + blog = pkgs.callPackage ./nix/package.nix { + siteUrl = "https://blog.jan-leila.com"; + }; + volpe = pkgs.callPackage ./nix/package.nix { + siteUrl = "https://volpe.jan-leila.com"; + }; }); devShells = forEachSupportedSystem ({pkgs}: { diff --git a/nix/configuration.nix b/nix/configuration.nix index bdc5787..8ec82a3 100644 --- a/nix/configuration.nix +++ b/nix/configuration.nix @@ -1,8 +1,4 @@ -{ - config, - pkgs, - ... -}: { +{...}: { imports = [ ./hardware-configuration.nix ./module.nix diff --git a/nix/module.nix b/nix/module.nix index c71a02b..2ddc24b 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -5,21 +5,35 @@ ... }: let cfg = config.services.volpe; - pkg = pkgs.callPackage ./package.nix {}; + + mkPkg = domain: + pkgs.callPackage ./package.nix { + siteUrl = "https://${domain}"; + }; + + allDomains = [cfg.domain] ++ cfg.extraDomains; + + mkVirtualHost = domain: { + root = "${mkPkg domain}"; + forceSSL = cfg.enableACME; + enableACME = cfg.enableACME; + locations."/" = { + tryFiles = "$uri $uri/ /index.html"; + }; + }; in { options.services.volpe = { enable = lib.mkEnableOption "volpe blog"; domain = lib.mkOption { type = lib.types.str; - default = "localhost"; description = "Primary domain name for nginx virtual host."; }; extraDomains = lib.mkOption { type = lib.types.listOf lib.types.str; default = []; - description = "Additional domain names (aliases) for the virtual host."; + description = "Additional domain names, each gets its own virtualHost."; }; enableACME = lib.mkOption { @@ -43,15 +57,12 @@ in { recommendedGzipSettings = true; recommendedProxySettings = true; - virtualHosts.${cfg.domain} = { - root = "${pkg}"; - serverAliases = cfg.extraDomains; - forceSSL = cfg.enableACME; - enableACME = cfg.enableACME; - locations."/" = { - tryFiles = "$uri $uri/ /index.html"; - }; - }; + # Create a virtualHost for each domain + virtualHosts = lib.listToAttrs (map (domain: { + name = domain; + value = mkVirtualHost domain; + }) + allDomains); }; security.acme = lib.mkIf cfg.enableACME { @@ -61,4 +72,4 @@ in { networking.firewall.allowedTCPPorts = [80 443]; }; -} \ No newline at end of file +} diff --git a/nix/package.nix b/nix/package.nix index ace602e..cc122ef 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -5,6 +5,7 @@ pnpm_10, fetchPnpmDeps, pnpmConfigHook, + siteUrl, }: let nodejs = nodejs_latest; pnpm = pnpm_10; @@ -31,7 +32,7 @@ in buildPhase = '' runHook preBuild - pnpm build + SITE_URL="${siteUrl}" pnpm build runHook postBuild ''; diff --git a/post-redirects.njk b/post-redirects.njk index d4c29ea..eb6f8cb 100644 --- a/post-redirects.njk +++ b/post-redirects.njk @@ -6,6 +6,7 @@ pagination: resolve: keys permalink: /post/{{ slugData }}/ layout: base.njk +excludeFromSitemap: true --- {% set posts = collections.postsBySlug[slugData] %} diff --git a/sitemap.njk b/sitemap.njk new file mode 100644 index 0000000..9d4582f --- /dev/null +++ b/sitemap.njk @@ -0,0 +1,15 @@ +--- +permalink: /sitemap.xml +eleventyExcludeFromCollections: true +--- + + + {%- for page in collections.all %} + {%- if page.url and page.url != "/sitemap.xml" and not page.data.excludeFromSitemap %} + + {{ site.url }}{{ page.url }} + {{ (page.data.updatedAt or page.data.createdAt or page.date) | isoDate }} + + {%- endif %} + {%- endfor %} + \ No newline at end of file