Skip to content

Returning lastUpdated page data in createContentLoader #3515

Closed Answered by Karlstens
Karlstens asked this question in Q&A
Discussion options

You must be logged in to vote

Just to comment here and thank @brc-dd for their great help, this script worked very well;

import { spawn } from "cross-spawn";
import fs from "fs";
import path from "path";
import pMap from "p-map";
import { createContentLoader } from "vitepress";

// Define the custom loader using createContentLoader
const loader = createContentLoader("/**/*.md", {
	async transform(rawData) {
		const data = await pMap(
			rawData,
			async (item) => {
				// console.log(item.url);
				const lastUpdated = await getLastUpdated(item.url);
				return { ...item, lastUpdated };
			},
			{ concurrency: 64 }
		);
		// Sort the data based on the lastUpdated field
		data.sort((a, b) => b.lastUpdated - a.lastUpdated)

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@brc-dd
Comment options

@Karlstens
Comment options

Comment options

You must be logged in to vote
1 reply
@Karlstens
Comment options

Answer selected by Karlstens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants