mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-07-21 20:55:56 -04:00
generate permalinks when parsing note
This commit is contained in:
+2
-2
@@ -25,9 +25,9 @@ export const buildFeed = () => {
|
||||
const notes = getAllNotes();
|
||||
notes.forEach((note: any) => {
|
||||
feed.addItem({
|
||||
guid: note.permalink,
|
||||
link: note.permalink,
|
||||
title: note.title,
|
||||
link: `${config.baseUrl}/notes/${note.slug}/`,
|
||||
guid: `${config.baseUrl}/notes/${note.slug}/`,
|
||||
description: note.description,
|
||||
image: note.image ? `${config.baseUrl}${note.image}` : "",
|
||||
author: [
|
||||
|
||||
+4
-3
@@ -2,17 +2,18 @@ import fs from "fs";
|
||||
import path from "path";
|
||||
import matter from "gray-matter";
|
||||
import { format, parseISO } from "date-fns";
|
||||
import { NOTES_DIR } from "./config";
|
||||
import * as config from "./config";
|
||||
|
||||
export const getNoteData = (file: string) => {
|
||||
const slug = file.replace(/\.mdx$/, "");
|
||||
const fullPath = path.join(process.cwd(), NOTES_DIR, `${slug}.mdx`);
|
||||
const fullPath = path.join(process.cwd(), config.NOTES_DIR, `${slug}.mdx`);
|
||||
const contents = fs.readFileSync(fullPath, "utf8");
|
||||
const { data } = matter(contents);
|
||||
|
||||
return {
|
||||
...data,
|
||||
slug,
|
||||
permalink: `${config.baseUrl}/notes/${slug}/`,
|
||||
date: parseISO(data.date).toISOString(), // validate/normalize the date string provided from front matter
|
||||
year: parseInt(format(parseISO(data.date), "yyyy")), // parse years here so it's easier to group them on list page
|
||||
};
|
||||
@@ -20,7 +21,7 @@ export const getNoteData = (file: string) => {
|
||||
|
||||
// all .mdx files in NOTES_DIR
|
||||
export const getNoteFiles = () =>
|
||||
fs.readdirSync(path.join(process.cwd(), NOTES_DIR)).filter((notePath) => /\.mdx$/.test(notePath));
|
||||
fs.readdirSync(path.join(process.cwd(), config.NOTES_DIR)).filter((notePath) => /\.mdx$/.test(notePath));
|
||||
|
||||
export const getAllNotes = () =>
|
||||
getNoteFiles()
|
||||
|
||||
Reference in New Issue
Block a user