Skip to content

Adding a "last edited" timestamp? #345

Answered by alexgleason
alexgleason asked this question in Q&A
Discussion options

You must be logged in to vote

Hey guys, I figured it out.

See: contentlayer.config.js

    lastModified: {
      type: 'string',
      resolve: (post) => getFileInfo(`_blog/${post._raw.sourceFilePath}`).lastModified,
    },
    sourceUrl: {
      type: 'string',
      resolve: (post) => getFileInfo(`_blog/${post._raw.sourceFilePath}`).sourceUrl,
    },

files.ts:

import { getLastModified } from './git';

interface FileInfo {
  lastModified: string
  sourceUrl: string
}

const getFileInfo = (filename: string): FileInfo => {
  return {
    lastModified: getLastModified(filename),
    sourceUrl: `https://gitlab.com/soapbox-pub/soapbox.pub/-/blob/main/${filename}`,
  };
};

export {
  getFileInfo,
};

git.ts:

import { execFi…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by alexgleason
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants