-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update how we display page last updated (#6110)
* Rename script to add last updated dates * Update to use imports * Add when page was last updated to left menu * Run script to flatten directory during prebuild command; add null check for directory data * Update amplify.yml to not run script to get last updated dates * Remove old LastUpdatedProvider * Remove old custom frontmatter remark plugin since we're no longer using it * Update src/styles/page-last-updated.scss Co-authored-by: Heather Buchel <hbuchel@gmail.com> * Add back layout changes (mistake from rebase) * Add page prop to show/hide page last updated date * Hide page last updated on home and overview pages --------- Co-authored-by: Heather Buchel <hbuchel@gmail.com>
- Loading branch information
Showing
20 changed files
with
124 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Text, View } from '@aws-amplify/ui-react'; | ||
import { PageNode } from 'src/directory/directory'; | ||
|
||
type PageLastUpdatedProps = { | ||
directoryData: PageNode; | ||
}; | ||
|
||
export function PageLastUpdated({ directoryData }: PageLastUpdatedProps) { | ||
if (directoryData) { | ||
const lastUpdated = directoryData['lastUpdated']; | ||
|
||
if (!lastUpdated) { | ||
return <></>; | ||
} | ||
|
||
const date = toReadableDate(lastUpdated); | ||
|
||
return ( | ||
<View className="page-last-updated"> | ||
<View className="page-last-updated__inner"> | ||
<Text fontSize="14px">Page updated {date}</Text>{' '} | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
return <></>; | ||
} | ||
|
||
function toReadableDate(date) { | ||
const dateOptions: Intl.DateTimeFormatOptions = { | ||
year: 'numeric', | ||
month: 'short', | ||
day: 'numeric' | ||
}; | ||
|
||
return new Date(date).toLocaleDateString('en-US', dateOptions); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { PageLastUpdated } from './PageLastUpdated'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { fileURLToPath } from 'url'; | ||
import path from 'path'; | ||
import { writeFile } from 'fs/promises'; | ||
import directory from './directory.json' assert { type: 'json' }; | ||
|
||
function flattenJSON(jsonObj, flattened = {}) { | ||
if (Array.isArray(jsonObj.children)) { | ||
jsonObj.children.forEach((child) => flattenJSON(child, flattened)); | ||
} | ||
if (jsonObj.route) { | ||
flattened[jsonObj.route] = { ...jsonObj }; | ||
// Remove the 'children' property since we don't need it in the "flat" structure | ||
delete flattened[jsonObj.route].children; | ||
} | ||
return flattened; | ||
} | ||
|
||
/** | ||
* Generate a "flat" version of directory.json | ||
*/ | ||
async function generateFlatDirectory() { | ||
const flatDirectory = flattenJSON(directory); | ||
|
||
try { | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
const filePath = path.join(__dirname, 'flatDirectory.json'); | ||
|
||
const json = JSON.stringify(flatDirectory, null, 2); | ||
|
||
await writeFile(filePath, json, 'utf-8'); | ||
|
||
console.log('Directory object has been written to', filePath); | ||
} catch (err) { | ||
throw new Error(`Error saving to flatDirectory.json: ${err}`); | ||
} | ||
} | ||
|
||
console.log('Generating flatDirectory.json...'); | ||
generateFlatDirectory(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.