feat: display last modified and wordcount on article
This commit is contained in:
parent
f8d69ac954
commit
666349c5b8
2 changed files with 11 additions and 5 deletions
|
@ -19,12 +19,16 @@ export async function getStaticPaths() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { entry } = Astro.props;
|
const { entry } = Astro.props;
|
||||||
const { Content, headings } = await entry.render();
|
const { Content, headings, remarkPluginFrontmatter } = await entry.render();
|
||||||
|
|
||||||
const noscript = siteConfig.noClientJavaScript
|
const noscript = siteConfig.noClientJavaScript
|
||||||
const slug = Astro.params.slug;
|
const slug = Astro.params.slug;
|
||||||
const author = Array.isArray(entry.data.author) ? entry.data.author : (entry.data.author !== undefined ? [entry.data.author] : [{collection: 'authors', id: siteConfig.defaultAuthor.id}]);
|
const author = Array.isArray(entry.data.author) ? entry.data.author : (entry.data.author !== undefined ? [entry.data.author] : [{collection: 'authors', id: siteConfig.defaultAuthor.id}]);
|
||||||
|
|
||||||
|
// Get Wordcount and Last Updated Date
|
||||||
|
const wordcount = remarkPluginFrontmatter.wordcount;
|
||||||
|
const lastUpdated = remarkPluginFrontmatter.lastModified;
|
||||||
|
|
||||||
// Get author data
|
// Get author data
|
||||||
const authorData = await Promise.all((author).map((singleAuthor) => getEntry(singleAuthor).then(authorEntry => authorEntry?.data)))
|
const authorData = await Promise.all((author).map((singleAuthor) => getEntry(singleAuthor).then(authorEntry => authorEntry?.data)))
|
||||||
const authorInfo = authorData.includes(undefined) ? [{data: siteConfig.defaultAuthor}] : authorData;
|
const authorInfo = authorData.includes(undefined) ? [{data: siteConfig.defaultAuthor}] : authorData;
|
||||||
|
@ -53,6 +57,9 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `
|
||||||
<h1 class="title">{entry.data.title}</h1>
|
<h1 class="title">{entry.data.title}</h1>
|
||||||
{authorInfo.map((a: any) => <AuthorInfo data={a} />)}
|
{authorInfo.map((a: any) => <AuthorInfo data={a} />)}
|
||||||
<span class="date">{new Date(entry.data.pubDate).toISOString().split('T')[0]}</span>
|
<span class="date">{new Date(entry.data.pubDate).toISOString().split('T')[0]}</span>
|
||||||
|
<span class="date">(Updated on {new Date(lastUpdated).toISOString().split('T')[0]})</span>
|
||||||
|
<span>|</span>
|
||||||
|
<span class="wordcount">{wordcount.words} words</span>
|
||||||
{headings.length !== 0 && <TableOfContents headings={headings} />}
|
{headings.length !== 0 && <TableOfContents headings={headings} />}
|
||||||
{entry.data.summary && <p class="summary">{entry.data.summary}</p> }
|
{entry.data.summary && <p class="summary">{entry.data.summary}</p> }
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { execSync } from "child_process";
|
import {execSync} from "child_process";
|
||||||
import { statSync } from "node:fs";
|
import {statSync} from "node:fs";
|
||||||
|
|
||||||
export function remarkModifiedTime() {
|
export function remarkModifiedTime() {
|
||||||
return function (tree, file) {
|
return function (tree, file) {
|
||||||
const filepath = file.history[0];
|
const filepath = file.history[0];
|
||||||
const result = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`).toString() || statSync(filepath).mtime.toISOString();
|
file.data.astro.frontmatter.lastModified = execSync(`git log -1 --pretty="format:%cI" "${filepath}"`).toString() || statSync(filepath).mtime.toISOString();
|
||||||
file.data.astro.frontmatter.lastModified = result.toString();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue