website: add update date for docs

This commit is contained in:
Johannes Kirschbauer 2024-03-25 11:47:43 +01:00 committed by Johannes Kirschbauer
parent ae6f0d0d4a
commit 00b137fb34
7 changed files with 95 additions and 1 deletions

View File

@ -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; };

21
website/nix/pdefs.nix vendored
View File

@ -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";
};

View File

@ -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",

View File

@ -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",

View File

@ -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}
</Typography>
{meta?.is_primop && meta.count_applied == 0 && (
<>
<Chip
@ -255,6 +258,9 @@ export default async function Page(props: { params: { path: string[] } }) {
)}
<ShareButton />
</Box>
<Box sx={{ pl: 4, m: 1 }} data-pagefind-ignore="all">
<LastUpdatedFromCommit {...upstreamInfo} />
</Box>
<Divider flexItem sx={{ mt: 2 }} />
<Box sx={{ display: "block" }}>

View File

@ -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);

View File

@ -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 (
<Tooltip title={`Upstream commit date: ${date.repr}`}>
<Chip
component="div"
label={
<span>
{"Docs pulled from | "}
<Link
href={`https://github.com/NixOS/nixpkgs/tree/${rev}`}
target="_blank"
rel="noopener noreferrer"
color="inherit"
>
This Revision
</Link>
{" | " + date.distance + " ago"}
</span>
}
variant="outlined"
color="primary"
size="small"
/>
</Tooltip>
);
};