From 00b137fb34db3d7546a38342287c1a9245f29eed Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Mon, 25 Mar 2024 11:47:43 +0100 Subject: [PATCH] website: add update date for docs --- pasta/flake-module.nix | 7 ++- website/nix/pdefs.nix | 21 +++++++++ website/package-lock.json | 15 +++++++ website/package.json | 1 + website/src/app/f/[...path]/page.tsx | 6 +++ .../components/ClientSideLayoutContext.tsx | 1 + .../src/components/LastUpdatedFromCommit.tsx | 45 +++++++++++++++++++ 7 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 website/src/components/LastUpdatedFromCommit.tsx diff --git a/pasta/flake-module.nix b/pasta/flake-module.nix index 6718068..457b920 100644 --- a/pasta/flake-module.nix +++ b/pasta/flake-module.nix @@ -3,6 +3,11 @@ let inherit (inputs'.nix.packages) nix; nixpkgs = self'.packages.nixpkgs-migrated; + + sourceInfo' = { + inherit (inputs.nixpkgs-master.sourceInfo) rev lastModified; + }; + metaFile = builtins.toFile "meta.json" (builtins.toJSON sourceInfo'); in { packages = { @@ -10,7 +15,7 @@ name = "pasta-meta"; src = ./.; buildPhase = '' - echo "\"${builtins.toJSON inputs.nixpkgs-master.rev}\"" > $out + cat ${metaFile} > $out ''; }; pasta = pkgs.callPackage ./default.nix { inherit nixpkgs nix pkgs; }; diff --git a/website/nix/pdefs.nix b/website/nix/pdefs.nix index e398b94..6224a7c 100644 --- a/website/nix/pdefs.nix +++ b/website/nix/pdefs.nix @@ -4616,6 +4616,19 @@ version = "1.0.8"; }; }; + date-fns = { + "3.6.0" = { + fetchInfo = { + narHash = "sha256-DQyJylOaiikHJ9QTCxdWaCghyTmeembq3pWc9D/gi9E="; + type = "tarball"; + url = "https://registry.npmjs.org/date-fns/-/date-fns-3.6.0.tgz"; + }; + ident = "date-fns"; + ltype = "file"; + treeInfo = { }; + version = "3.6.0"; + }; + }; debug = { "3.2.7" = { depInfo = { @@ -13860,6 +13873,11 @@ pin = "0.1.0"; runtime = true; }; + date-fns = { + descriptor = "^3.6.0"; + pin = "3.6.0"; + runtime = true; + }; eslint = { descriptor = "8.50.0"; pin = "8.50.0"; @@ -14907,6 +14925,9 @@ dev = true; key = "damerau-levenshtein/1.0.8"; }; + "node_modules/date-fns" = { + key = "date-fns/3.6.0"; + }; "node_modules/debug" = { key = "debug/4.3.4"; }; diff --git a/website/package-lock.json b/website/package-lock.json index a1e4cc4..1363201 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -21,6 +21,7 @@ "@next/mdx": "^14.0.4", "@types/mdx": "^2.0.10", "@vcarl/remark-headings": "^0.1.0", + "date-fns": "^3.6.0", "hast": "^1.0.0", "hast-util-to-string": "^3.0.0", "highlight.js": "^11.7.0", @@ -3470,6 +3471,15 @@ "integrity": "sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==", "dev": true }, + "node_modules/date-fns": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-3.6.0.tgz", + "integrity": "sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/kossnocorp" + } + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -14777,6 +14787,11 @@ "integrity": "sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==", "dev": true }, + "date-fns": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-3.6.0.tgz", + "integrity": "sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==" + }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", diff --git a/website/package.json b/website/package.json index 00b26fa..7bde836 100644 --- a/website/package.json +++ b/website/package.json @@ -22,6 +22,7 @@ "@next/mdx": "^14.0.4", "@types/mdx": "^2.0.10", "@vcarl/remark-headings": "^0.1.0", + "date-fns": "^3.6.0", "hast": "^1.0.0", "hast-util-to-string": "^3.0.0", "highlight.js": "^11.7.0", diff --git a/website/src/app/f/[...path]/page.tsx b/website/src/app/f/[...path]/page.tsx index 0abf09f..56eb609 100644 --- a/website/src/app/f/[...path]/page.tsx +++ b/website/src/app/f/[...path]/page.tsx @@ -11,9 +11,11 @@ import React, { Suspense } from "react"; import { PositionLink } from "@/components/PositionLink"; import { SearchNav } from "@/components/SearchNav"; +import upstreamInfo from "@/models/data/meta.json" assert { type: "json" }; import fs from "fs"; import path from "path"; import { Metadata, ResolvingMetadata } from "next"; +import { LastUpdatedFromCommit } from "@/components/LastUpdatedFromCommit"; // Important the key ("path") in the returned dict MUST match the dynamic path segment ([...path]) export async function generateStaticParams(): Promise<{ path: string[] }[]> { @@ -230,6 +232,7 @@ export default async function Page(props: { params: { path: string[] } }) { > {item?.meta.title} + {meta?.is_primop && meta.count_applied == 0 && ( <> + + + diff --git a/website/src/components/ClientSideLayoutContext.tsx b/website/src/components/ClientSideLayoutContext.tsx index 1b108a1..2f2d850 100644 --- a/website/src/components/ClientSideLayoutContext.tsx +++ b/website/src/components/ClientSideLayoutContext.tsx @@ -8,6 +8,7 @@ import { import { darkThemeOptions, lightThemeOptions } from "@/styles/theme"; import { ReactNode } from "react"; import { Toaster } from "react-hot-toast"; + const darkTheme = createTheme(darkThemeOptions); const lightTheme = createTheme(lightThemeOptions); diff --git a/website/src/components/LastUpdatedFromCommit.tsx b/website/src/components/LastUpdatedFromCommit.tsx new file mode 100644 index 0000000..798e400 --- /dev/null +++ b/website/src/components/LastUpdatedFromCommit.tsx @@ -0,0 +1,45 @@ +"use client"; + +import { useMemo } from "react"; +import { fromUnixTime, formatDistanceToNow, formatISO } from "date-fns"; +import { Chip, Link, Tooltip } from "@mui/material"; + +export const LastUpdatedFromCommit = ({ + lastModified, + rev, +}: { + lastModified: number; + rev: string; +}) => { + const date = useMemo(() => { + const date = fromUnixTime(lastModified); + return { + repr: formatISO(date, { representation: "date" }), + distance: formatDistanceToNow(date), + }; + }, [lastModified]); + return ( + + + {"Docs pulled from | "} + + This Revision + + {" | " + date.distance + " ago"} + + } + variant="outlined" + color="primary" + size="small" + /> + + ); +};