NixLabConnectionconnecting
ProjectsProject
web /

dreamstop.openfp.net

publicguest

dreamstop.openfp.net, the website and user manual of dreamstop, a language for continuous disambiguation

git clone git@nixlab.openfp.net:web/dreamstop.openfp.net.git
c46d9ab01fba5e4e33328e3479a8600176055ce4nix/site.nix
local:

{
  # The systems horizon-javascript offers a GHC for.
  systems = builtins.filter (s: local.inputs.horizon-javascript.legacyPackages.${s} ? ghc) (
    builtins.attrNames local.inputs.horizon-javascript.legacyPackages
  );

  perSystem =
    {
      config,
      pkgs,
      system,
      ...
    }:
    let
      inherit (local.inputs.nixpkgs) lib;
      inherit (local.inputs) design-kit;
      hl = pkgs.haskell.lib.compose;
      kit = import "${design-kit}/site.nix" { inherit pkgs; };

      jsSet = local.inputs.horizon-javascript.legacyPackages.${system};
      siteSet = config.legacyPackages;

      # The colour of each codepoint layer, and the codes in it, as the
      # manual's reference table lists them. The front page's stylesheet and
      # the manual's Typst show rules are both printed from this table. Every
      # colour reaches WCAG AA (4.5:1) on the page's white and zinc-100 surfaces.
      codepoints = {
        layers = {
          Force = {
            colour = "#b91c1c";
            codes = [
              "ASR"
              "DIR"
              "IRG"
              "DEC"
              "ADM"
              "CMS"
            ];
          };
          Mood = {
            colour = "#854d0e";
            codes = [
              "FAC"
              "HYP"
              "COU"
            ];
          };
          Aspect = {
            colour = "#1d4ed8";
            codes = [
              "PFV"
              "PRF"
              "PRG"
              "HAB"
            ];
          };
          Phase = {
            colour = "#7e22ce";
            codes = [
              "INC"
              "CSS"
              "CNT"
              "EXP"
            ];
          };
          Modality = {
            colour = "#047857";
            codes = [
              "DEO"
              "ABL"
              "TEL"
              "NEC"
              "WNC"
              "POS"
            ];
          };
          Negation = {
            colour = "#be185d";
            codes = [ "NEG" ];
          };
          Bound = {
            colour = "#9a3412";
            codes = [ "ONE" ];
          };
          Evidence = {
            colour = "#0e7490";
            codes = [
              "OBS"
              "PUP"
              "RPR"
              "INF"
              "REC"
            ];
          };
          Nominalisation = {
            colour = "#3f6212";
            codes = [
              "BSC"
              "OBJ"
            ];
          };
        };
        # Brackets, separators and positions.
        mark = "#52525b";
      };
      layerNames = builtins.attrNames codepoints.layers;
      # Each layer's colour as a class, and each code's class in its layer's
      # colour, for the front page.
      codepointsCss = pkgs.writeText "codepoints.css" (
        lib.concatMapStrings (
          l:
          lib.concatMapStrings (code: ".cp-${code}, ") codepoints.layers.${l}.codes
          + ".cp-${l} { color: ${codepoints.layers.${l}.colour}; }\n"
        ) layerNames
        + ".cp-mark { color: ${codepoints.mark}; }\n"
      );
      # The codepoints as a Typst module: `codepoints` colours every code in
      # the content it wraps, and `layers` lists each layer, in the order of
      # the manual's reference, with its colour and codes.
      layerOrder = [
        "Force"
        "Mood"
        "Aspect"
        "Phase"
        "Negation"
        "Modality"
        "Bound"
        "Evidence"
        "Nominalisation"
      ];
      codepointsTypst = pkgs.writeTextDir "codepoints.typ" (
        ''
          #let codepoints(body) = {
            let cp(col) = it => text(fill: rgb(col), it)
            show regex("[\\[\\]·]|/(rel|adv|comp)[0-9]+"): cp("${codepoints.mark}")
        ''
        + lib.concatMapStrings (
          l:
          "  show regex(\"\\\\b(${
              lib.concatStringsSep "|" codepoints.layers.${l}.codes
            })\\\\b\"): cp(\"${codepoints.layers.${l}.colour}\")\n"
        ) layerNames
        + ''
            body
          }
          #let layers = (
        ''
        + lib.concatMapStrings (
          l:
          "  (name: \"${l}\", colour: rgb(\"${codepoints.layers.${l}.colour}\"), codes: (${
              lib.concatMapStrings (code: "\"${code}\", ") codepoints.layers.${l}.codes
            })),\n"
        ) layerOrder
        + ''
          )
        ''
      );

      manualSources = [
        ../manual/dreamstop.typ
        ../manual/style.typ
        ../manual/introduction.typ
        ../manual/layers.typ
        ../manual/verdicts.typ
        ../manual/kinds.typ
        ../manual/limits.typ
        ../manual/reference.typ
        ../dreamstop.svg
        "${codepointsTypst}/codepoints.typ"
      ];

      manual = pkgs.runCommand "dreamstop.openfp.net-manual" { } ''
        mkdir -p $out/manual
        cp ${config.packages.dreamstop-pdf}/dreamstop.pdf $out/manual/dreamstop.pdf
      '';

      # The manual PDF holds the manual, with its reference of every code.
      manualSays =
        pkgs.runCommand "dreamstop.openfp.net-manual-says"
          {
            nativeBuildInputs = [ pkgs.poppler-utils ];
            LANG = "C.UTF-8";
            LC_ALL = "C.UTF-8";
          }
          ''
            pdftotext ${manual}/manual/dreamstop.pdf manual.txt
            grep -qiF "Reference of the codes" manual.txt || { echo "manual: the PDF holds no reference of the codes" >&2; exit 1; }
            touch $out
          '';

      name = "dreamstop";
      title = "dreamstop — a language for continuous disambiguation";
      description = "dreamstop is a language for continuous disambiguation. A program marks up every clause with codepoints, and authors rewrite any sentence that is not clear.";
      card = "https://dreamstop.openfp.net/og.png";
      forge = "https://nixlab.openfp.net";
      meta =
        key: n: value:
        ''<meta ${key}="${n}" content="${value}" />'';

      site = kit.mkSite {
        hsPkgs = siteSet;
        name = "dreamstop-openfp-net-web";
        static = [
          ../dreamstop.svg
          manual
        ];
        css = [
          ../dreamstop.css
          codepointsCss
        ];
        card = {
          svg = ../og.svg;
          extraFiles = [ ../dreamstop.svg ];
        };
        flakeLock = ../flake.lock;
        horizonVx = ../horizon.vx;
        expect = [
          ''<a class="btn" id="manual" href="manual/dreamstop.pdf">Read the manual</a>''
          { absent = "Ithkuil"; }
          { absent = "Continuous Disambiguation"; }
          ''<a href="${forge}/web/dreamstop.openfp.net">Page source</a>''
          ''<link rel="icon" href="dreamstop.svg"''
          ''<script src="site.js" defer></script>''
          (meta "property" "og:type" "website")
          (meta "property" "og:site_name" name)
          (meta "property" "og:title" title)
          (meta "name" "twitter:title" title)
          (meta "name" "description" description)
          (meta "property" "og:description" description)
          (meta "name" "twitter:description" description)
          (meta "property" "og:url" "https://dreamstop.openfp.net/")
          (meta "property" "og:image" card)
          (meta "name" "twitter:image" card)
          (meta "property" "og:image:width" "1200")
          (meta "property" "og:image:height" "627")
          (meta "property" "og:image:type" "image/png")
          (meta "name" "twitter:card" "summary_large_image")
        ];
        nojsText = [ "Read the manual" ];
      };

      cardCopy = pkgs.runCommand "dreamstop.openfp.net-card-copy" { } ''
        tagline=$(tr '\n' ' ' < ${../og.svg} | grep -oE '<text id="tagline".*' | sed -E 's#</text>.*##; s#<[^>]*># #g' | tr -s ' ' | sed -E 's/^ //; s/ $//')
        [ "$tagline" = "a language for continuous disambiguation" ] || { echo "card: the card must say the tagline, not '$tagline'" >&2; exit 1; }
        grep -qF '<image href="dreamstop.svg"' ${../og.svg} || { echo "card: the card must show the page's dreamstop.svg" >&2; exit 1; }
        touch $out
      '';
    in
    {
      horizon.overlay = {
        basePackages = jsSet;
        overlays = [
          (_final: prev: lib.mapAttrs (name: _: hl.dontHaddock prev.${name}) config.horizon.pkgs)
        ];
      };

      typst.docs.dreamstop = {
        src = ../manual/dreamstop.typ;
        extraFiles = builtins.tail manualSources;
      };

      packages = {
        default = site.package;
        inherit manual;
      };

      apps.serve = {
        type = "app";
        program = toString site.serve;
      };

      checks = site.checks // {
        card-copy = cardCopy;
        manual-says = manualSays;
      };
    };
}