Skip to content

Commit

Permalink
Merge pull request #241 from GSA/mmeyer/last-update
Browse files Browse the repository at this point in the history
Mmeyer/last update
  • Loading branch information
mark-meyer authored Mar 8, 2024
2 parents f7576f6 + 8b2318b commit e158d06
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 17 deletions.
2 changes: 2 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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 || '/'}],
Expand Down
3 changes: 3 additions & 0 deletions federalist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"fullClone": true
}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"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",
"@astrojs/mdx": "^2.1.1",
"@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"
},
Expand Down
22 changes: 22 additions & 0 deletions src/components/LastModified.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
const {last_modified} = Astro.props;
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
dayjs.extend(utc);
const updateDate = dayjs(last_modified)
.utc()
.format("MMMM DD, YYYY");
---
<div class="last-reviewed grid-container " id="page-last-reviewed">
Last updated: {updateDate}
</div>

<style>
.last-reviewed {
font-size: .75rem;
text-align: right;
margin-bottom: .5em;
}
</style>
1 change: 1 addition & 0 deletions src/content/about/domains-labor-categories/naics-codes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 3 additions & 1 deletion src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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, last_modified} = Astro.props;
---
<html lang="en">
<head>
Expand Down Expand Up @@ -36,6 +37,7 @@ const { title, description, show_site_link} = Astro.props;
<slot />
</div>
</div>
{last_modified && ( <LastModified last_modified={last_modified} /> )}
<USAIdentifier />
</div>
<script is:inline src={`${import.meta.env.BASE_URL}js/uswds.min.js`}></script>
Expand Down
6 changes: 3 additions & 3 deletions src/layouts/PageLayout.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
import BaseLayout from "@layouts/BaseLayout.astro";
const { title, description } = Astro.props;
const { title, description, last_modified } = Astro.props;
---
<BaseLayout title={title} description={description}>

<BaseLayout title={title} description={description} last_modified={last_modified}>
<section class="grid-container usa-section">
<div class="grid-row grid-gap">
<slot />
Expand Down
5 changes: 3 additions & 2 deletions src/pages/about/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ export async function getStaticPaths() {
}
const { entry, pages } = Astro.props;
const { Content, headings } = await entry.render();
const { Content, headings, remarkPluginFrontmatter:{last_modified} } = await entry.render();
---
<PageLayout title={entry.data.title} description={entry.data.description}>
<PageLayout title={entry.data.title} description={entry.data.description} last_modified={last_modified}>
<SideNav
title="About the GSA SmartPay Program"
parent_path="about"
Expand Down
4 changes: 2 additions & 2 deletions src/pages/buyers-guide/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export async function getStaticPaths() {
})
}
const { entry, pages } = Astro.props;
const { Content, headings } = await entry.render();
const { Content, headings, remarkPluginFrontmatter:{last_modified} } = await entry.render();
---
<PageLayout title={entry.data.title} description={entry.data.description}>
<PageLayout title={entry.data.title} description={entry.data.description} last_modified={last_modified}>
{entry.data.order == 0 ?
(
<PageContentLayoutWideScreen title={entry.data.title}>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/contact.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import PageLayout from '@layouts/PageLayout.astro'
const entry = await getEntry('contact', 'index');
const { Content} = await entry.render();
const { Content, remarkPluginFrontmatter:{last_modified}} = await entry.render();
---
<PageLayout title={entry.data.title} description={entry.data.description}>
<PageLayout title={entry.data.title} description={entry.data.description} last_modified={last_modified}>
<PageContentLayoutWideScreen title={entry.data.title}>
<div class="usa-prose">
<Content />
Expand Down
4 changes: 2 additions & 2 deletions src/pages/events-training.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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:{last_modified}} = await entry.render();
---
<PageLayout title={entry.data.title} description={entry.data.description}>
<PageLayout title={entry.data.title} description={entry.data.description} last_modified={last_modified}>
<PageContentLayoutWideScreen title={entry.data.title}>
<div class="usa-prose">
<Content />
Expand Down
4 changes: 2 additions & 2 deletions src/pages/resources/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import PageLayout from '@layouts/PageLayout.astro'
const entry = await getEntry('resources', 'index');
const { Content} = await entry.render();
const { Content, remarkPluginFrontmatter:{last_modified} } = await entry.render();
---
<PageLayout title={entry.data.title} description={entry.data.description}>
<PageLayout title={entry.data.title} description={entry.data.description} last_modified={last_modified}>
<PageContentLayoutWideScreen title={entry.data.title}>
<div class="usa-prose oasis-resourcetable">
<Content />
Expand Down
4 changes: 2 additions & 2 deletions src/pages/sellers-guide/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export async function getStaticPaths() {
})
}
const { entry, pages } = Astro.props;
const { Content, headings } = await entry.render();
const { Content, headings, remarkPluginFrontmatter:{last_modified} } = await entry.render();
---
<PageLayout title={entry.data.title} description={entry.data.description}>
<PageLayout title={entry.data.title} description={entry.data.description} last_modified={last_modified}>
{entry.data.order == 0 ?
(
<PageContentLayoutWideScreen title={entry.data.title}>
Expand Down
29 changes: 29 additions & 0 deletions src/plugins/remark-modified-time.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 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.
*
* 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() {
return function (tree, file) {
// 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.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.last_modified = result.toString();
}
};
}

0 comments on commit e158d06

Please sign in to comment.