From d0ec4139fc9ad0f76866217aa23d9e462ad125ce Mon Sep 17 00:00:00 2001 From: Mark Meyer Date: Thu, 7 Mar 2024 13:57:11 -0900 Subject: [PATCH 1/7] test out lastmodified to see if it works with pages --- astro.config.mjs | 2 ++ package-lock.json | 6 ++++++ package.json | 2 +- src/components/LastModified.astro | 22 ++++++++++++++++++++++ src/layouts/PageLayout.astro | 8 ++++++-- src/pages/about/[...slug].astro | 5 +++-- src/pages/buyers-guide/[...slug].astro | 4 ++-- src/pages/contact.astro | 4 ++-- src/pages/events-training.astro | 4 ++-- src/pages/resources/index.astro | 4 ++-- src/pages/sellers-guide/[...slug].astro | 4 ++-- src/plugins/remark-modified-time.mjs | 9 +++++++++ 12 files changed, 59 insertions(+), 15 deletions(-) create mode 100644 src/components/LastModified.astro create mode 100644 src/plugins/remark-modified-time.mjs diff --git a/astro.config.mjs b/astro.config.mjs index 522c846d..11206db5 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -5,6 +5,7 @@ import { defineConfig } from 'astro/config'; import process_anchors from "./src/plugins/process_anchors"; import process_image_urls from './src/plugins/process_image_urls'; import table_row_headers from './src/plugins/table_row_headers'; +import { remarkModifiedTime } from './src/plugins/remark-modified-time.mjs'; const BASE_PATH = "/oasis-plus" @@ -26,6 +27,7 @@ export default defineConfig({ base: process.env.BASEURL, trailingSlash: 'always', markdown: { + remarkPlugins: [remarkModifiedTime], rehypePlugins: [ [table_row_headers, {}], [process_anchors, {baseURL: process.env.BASEURL || '/'}], diff --git a/package-lock.json b/package-lock.json index 303c32c9..bb610562 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@astrojs/sitemap": "^3.1.1", "@uswds/uswds": "3.7.1", "astro": "^4.4.11", + "dayjs": "^1.11.10", "typescript": "^5.3.3", "unist-util-visit": "^5.0.0" }, @@ -3906,6 +3907,11 @@ "type": "^1.0.1" } }, + "node_modules/dayjs": { + "version": "1.11.10", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz", + "integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==" + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", diff --git a/package.json b/package.json index 95b10cb7..790a4e46 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "pa11y-ci:desktop": "pa11y-ci --config ./.pa11yci-desktop --sitemap http://localhost:4321/sitemap-0.xml --sitemap-find \"^https://www.gsa.gov/oasis-plus/\" --sitemap-replace \"http://localhost:4321/\"", "pa11y-ci:mobile": "pa11y-ci --config ./.pa11yci-mobile --sitemap http://localhost:4321/sitemap-0.xml --sitemap-find \"^https://www.gsa.gov/oasis-plus/\" --sitemap-replace \"http://localhost:4321/\"", "pa11y-ci:gh": "npx start-server-and-test serve http://localhost:4321 pa11y-ci" - }, "dependencies": { "@astrojs/check": "^0.5.6", @@ -24,6 +23,7 @@ "@astrojs/sitemap": "^3.1.1", "@uswds/uswds": "3.7.1", "astro": "^4.4.11", + "dayjs": "^1.11.10", "typescript": "^5.3.3", "unist-util-visit": "^5.0.0" }, diff --git a/src/components/LastModified.astro b/src/components/LastModified.astro new file mode 100644 index 00000000..4c0bef46 --- /dev/null +++ b/src/components/LastModified.astro @@ -0,0 +1,22 @@ +--- +const {lastModified} = Astro.props; +import dayjs from "dayjs"; +import utc from "dayjs/plugin/utc"; + +dayjs.extend(utc); + +const updateDate = dayjs(lastModified) + .utc() + .format("MMMM DD, YYYY"); +--- +
+ Last updated: {updateDate} +
+ + \ No newline at end of file diff --git a/src/layouts/PageLayout.astro b/src/layouts/PageLayout.astro index 2c24b2d2..d1cc81f2 100644 --- a/src/layouts/PageLayout.astro +++ b/src/layouts/PageLayout.astro @@ -1,12 +1,16 @@ --- import BaseLayout from "@layouts/BaseLayout.astro"; -const { title, description } = Astro.props; +import LastModified from "@components/LastModified.astro" +const { title, description, lastModified=undefined } = Astro.props; + --- -
+ {lastModified && ( + + )}
\ No newline at end of file diff --git a/src/pages/about/[...slug].astro b/src/pages/about/[...slug].astro index 5c1536ab..ea6ec3b4 100644 --- a/src/pages/about/[...slug].astro +++ b/src/pages/about/[...slug].astro @@ -14,9 +14,10 @@ export async function getStaticPaths() { } const { entry, pages } = Astro.props; -const { Content, headings } = await entry.render(); +const { Content, headings, remarkPluginFrontmatter:{lastModified} } = await entry.render(); + --- - + + {entry.data.order == 0 ? ( diff --git a/src/pages/contact.astro b/src/pages/contact.astro index a404bdb9..d06f2389 100644 --- a/src/pages/contact.astro +++ b/src/pages/contact.astro @@ -5,10 +5,10 @@ import PageLayout from '@layouts/PageLayout.astro' const entry = await getEntry('contact', 'index'); -const { Content} = await entry.render(); +const { Content, remarkPluginFrontmatter:{lastModified}} = await entry.render(); --- - +
diff --git a/src/pages/events-training.astro b/src/pages/events-training.astro index 1a78edfb..19c008b3 100644 --- a/src/pages/events-training.astro +++ b/src/pages/events-training.astro @@ -5,10 +5,10 @@ import PageLayout from '@layouts/PageLayout.astro' const entry = await getEntry('events-training', 'index'); -const { Content} = await entry.render(); +const { Content, remarkPluginFrontmatter:{lastModified}} = await entry.render(); --- - +
diff --git a/src/pages/resources/index.astro b/src/pages/resources/index.astro index b79ecd30..48623ec6 100644 --- a/src/pages/resources/index.astro +++ b/src/pages/resources/index.astro @@ -5,10 +5,10 @@ import PageLayout from '@layouts/PageLayout.astro' const entry = await getEntry('resources', 'index'); -const { Content} = await entry.render(); +const { Content, remarkPluginFrontmatter:{lastModified} } = await entry.render(); --- - +
diff --git a/src/pages/sellers-guide/[...slug].astro b/src/pages/sellers-guide/[...slug].astro index 006894ea..61f4a5db 100644 --- a/src/pages/sellers-guide/[...slug].astro +++ b/src/pages/sellers-guide/[...slug].astro @@ -13,9 +13,9 @@ export async function getStaticPaths() { }) } const { entry, pages } = Astro.props; -const { Content, headings } = await entry.render(); +const { Content, headings, remarkPluginFrontmatter:{lastModified} } = await entry.render(); --- - + {entry.data.order == 0 ? ( diff --git a/src/plugins/remark-modified-time.mjs b/src/plugins/remark-modified-time.mjs new file mode 100644 index 00000000..922fdd2c --- /dev/null +++ b/src/plugins/remark-modified-time.mjs @@ -0,0 +1,9 @@ +import { execSync } from "child_process"; + +export function remarkModifiedTime() { + return function (tree, file) { + const filepath = file.history[0]; + const result = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`); + file.data.astro.frontmatter.lastModified = result.toString(); + }; +} \ No newline at end of file From 94b1bcd3d9b23404a202698e846694caaf3999cd Mon Sep 17 00:00:00 2001 From: Mark Meyer Date: Thu, 7 Mar 2024 14:12:50 -0900 Subject: [PATCH 2/7] temporarily write logs on build to debug --- src/plugins/remark-modified-time.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/remark-modified-time.mjs b/src/plugins/remark-modified-time.mjs index 922fdd2c..ff3b03df 100644 --- a/src/plugins/remark-modified-time.mjs +++ b/src/plugins/remark-modified-time.mjs @@ -5,5 +5,6 @@ export function remarkModifiedTime() { const filepath = file.history[0]; const result = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`); file.data.astro.frontmatter.lastModified = result.toString(); + console.log("file:", filepath, "date:", result.toString()) }; } \ No newline at end of file From a7fb33bf5d9b78adbecdead22d85708189205e2e Mon Sep 17 00:00:00 2001 From: Mark Meyer Date: Thu, 7 Mar 2024 14:35:58 -0900 Subject: [PATCH 3/7] add federalist.json to pull full clone --- federalist.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 federalist.json diff --git a/federalist.json b/federalist.json new file mode 100644 index 00000000..87cc366b --- /dev/null +++ b/federalist.json @@ -0,0 +1,3 @@ +{ + "fullClone": true +} \ No newline at end of file From e7f6c60735b06e09111947adb6e60b1b8cd4c801 Mon Sep 17 00:00:00 2001 From: Mark Meyer Date: Thu, 7 Mar 2024 15:09:22 -0900 Subject: [PATCH 4/7] remove debug loggin, add federalist.json to specify deep clones --- src/layouts/BaseLayout.astro | 4 +++- src/layouts/PageLayout.astro | 8 ++------ src/plugins/remark-modified-time.mjs | 11 ++++++++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/layouts/BaseLayout.astro b/src/layouts/BaseLayout.astro index 82d14592..8369db32 100644 --- a/src/layouts/BaseLayout.astro +++ b/src/layouts/BaseLayout.astro @@ -2,8 +2,9 @@ import GSAHeader from '@components/GSAHeader.astro'; import USAIdentifier from '@components/USAIdentifier.astro'; import Banner from '@components/Banner.astro'; +import LastModified from "@components/LastModified.astro" -const { title, description, show_site_link} = Astro.props; +const { title, description, show_site_link, lastModified=undefined} = Astro.props; --- @@ -36,6 +37,7 @@ const { title, description, show_site_link} = Astro.props;
+ {lastModified && ( )}
diff --git a/src/layouts/PageLayout.astro b/src/layouts/PageLayout.astro index d1cc81f2..3ecc1a28 100644 --- a/src/layouts/PageLayout.astro +++ b/src/layouts/PageLayout.astro @@ -1,16 +1,12 @@ --- import BaseLayout from "@layouts/BaseLayout.astro"; -import LastModified from "@components/LastModified.astro" -const { title, description, lastModified=undefined } = Astro.props; +const { title, description, lastModified } = Astro.props; --- - +
- {lastModified && ( - - )}
\ No newline at end of file diff --git a/src/plugins/remark-modified-time.mjs b/src/plugins/remark-modified-time.mjs index ff3b03df..ecbbe1e6 100644 --- a/src/plugins/remark-modified-time.mjs +++ b/src/plugins/remark-modified-time.mjs @@ -1,3 +1,13 @@ +/** + * This looks at the last git commit of the markdown files to determin the + * modification date. + * + * When running on cloud.gov pages, it is important to tell cloud.gov to clone + * the full repo — the default is a shallow clone. + * + * This is specified in the root-level federalist.json file + * See: https://cloud.gov/pages/documentation/federalist-json/ + */ import { execSync } from "child_process"; export function remarkModifiedTime() { @@ -5,6 +15,5 @@ export function remarkModifiedTime() { const filepath = file.history[0]; const result = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`); file.data.astro.frontmatter.lastModified = result.toString(); - console.log("file:", filepath, "date:", result.toString()) }; } \ No newline at end of file From 49ccc0e7f99e896e06bf699f2658d3fdf12d508a Mon Sep 17 00:00:00 2001 From: Mark Meyer Date: Fri, 8 Mar 2024 08:37:30 -0900 Subject: [PATCH 5/7] allow manually setting last-modified in front matter for cases when the data is not directly in the markdown (like the naics codes). --- .../domains-labor-categories/naics-codes.mdx | 1 + src/layouts/BaseLayout.astro | 2 +- src/plugins/remark-modified-time.mjs | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/content/about/domains-labor-categories/naics-codes.mdx b/src/content/about/domains-labor-categories/naics-codes.mdx index 340cf585..0d27cee8 100644 --- a/src/content/about/domains-labor-categories/naics-codes.mdx +++ b/src/content/about/domains-labor-categories/naics-codes.mdx @@ -3,6 +3,7 @@ title: NAICS codes by domain description: "Each OASIS+ domain contains multiple North American Industry Classification System (NAICS) codes. Learn which NAICs codes crosswalk to each domain." order: 3 is_child: true +last_modified: "February 27, 2024" --- import NAICSDomainTables from "@components/NAICSDomainTables.astro"; diff --git a/src/layouts/BaseLayout.astro b/src/layouts/BaseLayout.astro index 8369db32..e1c96a82 100644 --- a/src/layouts/BaseLayout.astro +++ b/src/layouts/BaseLayout.astro @@ -4,7 +4,7 @@ import USAIdentifier from '@components/USAIdentifier.astro'; import Banner from '@components/Banner.astro'; import LastModified from "@components/LastModified.astro" -const { title, description, show_site_link, lastModified=undefined} = Astro.props; +const { title, description, show_site_link, lastModified} = Astro.props; --- diff --git a/src/plugins/remark-modified-time.mjs b/src/plugins/remark-modified-time.mjs index ecbbe1e6..09f109e2 100644 --- a/src/plugins/remark-modified-time.mjs +++ b/src/plugins/remark-modified-time.mjs @@ -1,7 +1,10 @@ /** - * This looks at the last git commit of the markdown files to determin the + * This looks at the last git commit of the markdown files to determine the * modification date. * + * Alternatively users may override this date by adding a last_modified key to front-matter + * with the date as a string. + * * When running on cloud.gov pages, it is important to tell cloud.gov to clone * the full repo — the default is a shallow clone. * @@ -12,8 +15,15 @@ import { execSync } from "child_process"; export function remarkModifiedTime() { return function (tree, file) { - const filepath = file.history[0]; - const result = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`); - file.data.astro.frontmatter.lastModified = result.toString(); + // allow content creators to override date in front-matter + const manual_last_modified_date = file.data.astro.frontmatter.last_modified + if (manual_last_modified_date) { + file.data.astro.frontmatter.lastModified = manual_last_modified_date + } + else { + const filepath = file.history[0]; + const result = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`); + file.data.astro.frontmatter.lastModified = result.toString(); + } }; } \ No newline at end of file From 096aabfc504703a8e053f06686f709a4d8f1e00f Mon Sep 17 00:00:00 2001 From: Mark Meyer Date: Fri, 8 Mar 2024 08:45:12 -0900 Subject: [PATCH 6/7] remove camlecase for last_modified --- src/components/LastModified.astro | 4 ++-- src/layouts/BaseLayout.astro | 4 ++-- src/layouts/PageLayout.astro | 4 ++-- src/pages/about/[...slug].astro | 4 ++-- src/pages/buyers-guide/[...slug].astro | 4 ++-- src/pages/contact.astro | 4 ++-- src/pages/events-training.astro | 4 ++-- src/pages/resources/index.astro | 4 ++-- src/pages/sellers-guide/[...slug].astro | 4 ++-- src/plugins/remark-modified-time.mjs | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/components/LastModified.astro b/src/components/LastModified.astro index 4c0bef46..3776e769 100644 --- a/src/components/LastModified.astro +++ b/src/components/LastModified.astro @@ -1,11 +1,11 @@ --- -const {lastModified} = Astro.props; +const {last_modified} = Astro.props; import dayjs from "dayjs"; import utc from "dayjs/plugin/utc"; dayjs.extend(utc); -const updateDate = dayjs(lastModified) +const updateDate = dayjs(last_modified) .utc() .format("MMMM DD, YYYY"); --- diff --git a/src/layouts/BaseLayout.astro b/src/layouts/BaseLayout.astro index e1c96a82..2da5c455 100644 --- a/src/layouts/BaseLayout.astro +++ b/src/layouts/BaseLayout.astro @@ -4,7 +4,7 @@ import USAIdentifier from '@components/USAIdentifier.astro'; import Banner from '@components/Banner.astro'; import LastModified from "@components/LastModified.astro" -const { title, description, show_site_link, lastModified} = Astro.props; +const { title, description, show_site_link, last_modified} = Astro.props; --- @@ -37,7 +37,7 @@ const { title, description, show_site_link, lastModified} = Astro.props; - {lastModified && ( )} + {last_modified && ( )} diff --git a/src/layouts/PageLayout.astro b/src/layouts/PageLayout.astro index 3ecc1a28..2fe2f188 100644 --- a/src/layouts/PageLayout.astro +++ b/src/layouts/PageLayout.astro @@ -1,9 +1,9 @@ --- import BaseLayout from "@layouts/BaseLayout.astro"; -const { title, description, lastModified } = Astro.props; +const { title, description, last_modified } = Astro.props; --- - +
diff --git a/src/pages/about/[...slug].astro b/src/pages/about/[...slug].astro index ea6ec3b4..95cd7d50 100644 --- a/src/pages/about/[...slug].astro +++ b/src/pages/about/[...slug].astro @@ -14,10 +14,10 @@ export async function getStaticPaths() { } const { entry, pages } = Astro.props; -const { Content, headings, remarkPluginFrontmatter:{lastModified} } = await entry.render(); +const { Content, headings, remarkPluginFrontmatter:{last_modified} } = await entry.render(); --- - + + {entry.data.order == 0 ? ( diff --git a/src/pages/contact.astro b/src/pages/contact.astro index d06f2389..7d10dfa7 100644 --- a/src/pages/contact.astro +++ b/src/pages/contact.astro @@ -5,10 +5,10 @@ import PageLayout from '@layouts/PageLayout.astro' const entry = await getEntry('contact', 'index'); -const { Content, remarkPluginFrontmatter:{lastModified}} = await entry.render(); +const { Content, remarkPluginFrontmatter:{last_modified}} = await entry.render(); --- - +
diff --git a/src/pages/events-training.astro b/src/pages/events-training.astro index 19c008b3..9437b578 100644 --- a/src/pages/events-training.astro +++ b/src/pages/events-training.astro @@ -5,10 +5,10 @@ import PageLayout from '@layouts/PageLayout.astro' const entry = await getEntry('events-training', 'index'); -const { Content, remarkPluginFrontmatter:{lastModified}} = await entry.render(); +const { Content, remarkPluginFrontmatter:{last_modified}} = await entry.render(); --- - +
diff --git a/src/pages/resources/index.astro b/src/pages/resources/index.astro index 48623ec6..aebb3bc8 100644 --- a/src/pages/resources/index.astro +++ b/src/pages/resources/index.astro @@ -5,10 +5,10 @@ import PageLayout from '@layouts/PageLayout.astro' const entry = await getEntry('resources', 'index'); -const { Content, remarkPluginFrontmatter:{lastModified} } = await entry.render(); +const { Content, remarkPluginFrontmatter:{last_modified} } = await entry.render(); --- - +
diff --git a/src/pages/sellers-guide/[...slug].astro b/src/pages/sellers-guide/[...slug].astro index 61f4a5db..8311fe9c 100644 --- a/src/pages/sellers-guide/[...slug].astro +++ b/src/pages/sellers-guide/[...slug].astro @@ -13,9 +13,9 @@ export async function getStaticPaths() { }) } const { entry, pages } = Astro.props; -const { Content, headings, remarkPluginFrontmatter:{lastModified} } = await entry.render(); +const { Content, headings, remarkPluginFrontmatter:{last_modified} } = await entry.render(); --- - + {entry.data.order == 0 ? ( diff --git a/src/plugins/remark-modified-time.mjs b/src/plugins/remark-modified-time.mjs index 09f109e2..9ca7a784 100644 --- a/src/plugins/remark-modified-time.mjs +++ b/src/plugins/remark-modified-time.mjs @@ -18,12 +18,12 @@ export function remarkModifiedTime() { // allow content creators to override date in front-matter const manual_last_modified_date = file.data.astro.frontmatter.last_modified if (manual_last_modified_date) { - file.data.astro.frontmatter.lastModified = manual_last_modified_date + file.data.astro.frontmatter.last_modified = manual_last_modified_date } else { const filepath = file.history[0]; const result = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`); - file.data.astro.frontmatter.lastModified = result.toString(); + file.data.astro.frontmatter.last_modified = result.toString(); } }; } \ No newline at end of file From 8b2318bac32b7b7979bd148d0550cf9135f8a3ea Mon Sep 17 00:00:00 2001 From: Mark Meyer Date: Fri, 8 Mar 2024 08:47:17 -0900 Subject: [PATCH 7/7] fix description typo --- src/pages/resources/index.astro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/resources/index.astro b/src/pages/resources/index.astro index aebb3bc8..43cc3681 100644 --- a/src/pages/resources/index.astro +++ b/src/pages/resources/index.astro @@ -8,7 +8,7 @@ const entry = await getEntry('resources', 'index'); const { Content, remarkPluginFrontmatter:{last_modified} } = await entry.render(); --- - +