data pages for listing everything json, each category and each service under a category, bordel de merde for the time being
This commit is contained in:
parent
1998709a8a
commit
d73bac59a8
|
@ -0,0 +1,20 @@
|
||||||
|
import { PageServerLoad } from './$types';
|
||||||
|
import { readJsonFile } from '$lib/utils/formatParse';
|
||||||
|
|
||||||
|
export const load: PageServerLoad = async () => {
|
||||||
|
const categoriesDir = path.join(process.cwd(), 'src', 'content');
|
||||||
|
const categoryDirs = fs.readdirSync(categoriesDir).filter(dir => fs.lstatSync(path.join(categoriesDir, dir)).isDirectory());
|
||||||
|
|
||||||
|
const services = categoryDirs.map(categoryDir => {
|
||||||
|
const category = readJsonFile(`${categoryDirs}/${categoryDir}.json`);
|
||||||
|
return { category: categoryDir, items: category };
|
||||||
|
});
|
||||||
|
|
||||||
|
return { props: { services } };
|
||||||
|
}
|
||||||
|
|
||||||
|
// export const load: = async () => {
|
||||||
|
// return {
|
||||||
|
// posts: listPosts()
|
||||||
|
// };
|
||||||
|
// };
|
|
@ -0,0 +1,31 @@
|
||||||
|
import type { ExtendedCategory } from '$lib/types';
|
||||||
|
|
||||||
|
import { promises as fs } from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import { parseMarkdown } from '$lib/markdownParser';
|
||||||
|
import type { ExtendedCategory } from '$lib/types';
|
||||||
|
|
||||||
|
export async function get({ params }) {
|
||||||
|
const { category, service } = params;
|
||||||
|
|
||||||
|
// Read the JSON file for the service
|
||||||
|
const jsonPath = path.join('src', 'content', category, service, `${service}.json`);
|
||||||
|
const jsonContent = await fs.readFile(jsonPath, 'utf-8');
|
||||||
|
const serviceData = JSON.parse(jsonContent);
|
||||||
|
|
||||||
|
// Read the markdown file for the service
|
||||||
|
const markdownPath = path.join('src', 'content', category, service, `${service}.md`);
|
||||||
|
const markdownContent = await fs.readFile(markdownPath, 'utf-8');
|
||||||
|
const { frontmatter, headings } = parseMarkdown(markdownContent);
|
||||||
|
|
||||||
|
// Combine the service data with the frontmatter and headings to create the extended service
|
||||||
|
const ExtendedCategory: ExtendedCategory = {
|
||||||
|
...serviceData,
|
||||||
|
...frontmatter,
|
||||||
|
headings,
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
body: ExtendedCategory,
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,134 @@
|
||||||
|
|
||||||
|
// import type { PageLoad } from './$types';
|
||||||
|
// import servicesData from '$lib/services.json'; // Assuming you have a JSON file with all the data
|
||||||
|
|
||||||
|
// export const load: PageLoad = async ({ params }) => {
|
||||||
|
// const { category, service } = params;
|
||||||
|
// const serviceItem = servicesData.find((s) => s.category === category)?.items.find((item) => item.id === service);
|
||||||
|
|
||||||
|
// if (!serviceItem) {
|
||||||
|
// throw new Error('Service not found');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// props: {
|
||||||
|
// openGraphData: {
|
||||||
|
// title: serviceItem.title,
|
||||||
|
// description: serviceItem.description,
|
||||||
|
// image: serviceItem.image,
|
||||||
|
// // ...other OpenGraph data...
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
// };
|
||||||
|
// import { promises as fs } from 'fs';
|
||||||
|
// import path from 'path';
|
||||||
|
// import type { PageServerLoad } from './$types';
|
||||||
|
// import { parseMarkdown } from '$lib/markdownParser'; // You'll need to create this
|
||||||
|
// import servicesData from '$lib/services.json';
|
||||||
|
// import type { ExtendedServiceItem, MarkdownFrontmatter } from '$lib/types';
|
||||||
|
|
||||||
|
// export const load: PageServerLoad = async ({ params }) => {
|
||||||
|
// const { category, service } = params;
|
||||||
|
|
||||||
|
// // Read the markdown file for the service with grey matter
|
||||||
|
// const markdownPath = path.join('src', 'content', 'posts', category, service, 'content.md');
|
||||||
|
// const markdownContent = await fs.readFile(markdownPath, 'utf-8');
|
||||||
|
// const { frontmatter } = parseMarkdown<MarkdownFrontmatter>(markdownContent);
|
||||||
|
|
||||||
|
// // Find the service item in the JSON data
|
||||||
|
// const serviceItem = servicesData.find((s) => s.category === category)?.items.find((item) => item.id === service);
|
||||||
|
|
||||||
|
// if (!serviceItem) {
|
||||||
|
// throw new Error('Service not found');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Combine the service item with the frontmatter to create the extended service item
|
||||||
|
// const extendedServiceItem: ExtendedServiceItem = {
|
||||||
|
// ...serviceItem,
|
||||||
|
// ...frontmatter,
|
||||||
|
// };
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// props: {
|
||||||
|
// openGraphData: extendedServiceItem,
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
// };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import { promises as fs } from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import * as conf from '$lib/config'
|
||||||
|
import { readJsonFile, parseMarkdownFile } from '$lib/utils';
|
||||||
|
import { parseMarkdown } from '$lib/markdownParser';
|
||||||
|
import type { ExtendedService } from '$lib/types';
|
||||||
|
|
||||||
|
export const load:PageLoad = async ({ params }) => {
|
||||||
|
const { category, service } = params;
|
||||||
|
|
||||||
|
// Read the JSON file for the service
|
||||||
|
const categoryJSON = readJsonFile(`${params.category}/${params.category}.json`);
|
||||||
|
const serviceData = categoryJSON.find(service => service.id === params.service);
|
||||||
|
|
||||||
|
if (!service) {
|
||||||
|
throw new Error(`Service not found: ${params.service}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the markdown file for the service
|
||||||
|
const markdownData = parseMarkdownFile(`${params.category}/${params.service}/${params.service}.md`);
|
||||||
|
const markdownPath = path.join('src', 'content', category, service, `${service}.md`);
|
||||||
|
const markdownContent = await fs.readFile(markdownPath, 'utf-8');
|
||||||
|
const frontmatter = parseMarkdown(markdownContent);
|
||||||
|
// headings here instead of remark plugin custom?
|
||||||
|
// Combine the service data with the frontmatter and headings to create the extended service
|
||||||
|
const extendedService: ExtendedService = {
|
||||||
|
...serviceData,
|
||||||
|
...frontmatter,
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
extendedService,
|
||||||
|
og: {
|
||||||
|
title: extendedService.title,
|
||||||
|
type: 'article',
|
||||||
|
image: extendedService.image,
|
||||||
|
url: `https://yourwebsite.com/services/${params.category}/${params.service}`,
|
||||||
|
description: extendedService.description,
|
||||||
|
published_time: extendedService.frontmatter.date,
|
||||||
|
tags: extendedService.frontmatter.tags
|
||||||
|
}}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export async function load({ params }) {
|
||||||
|
const category = readJsonFile(`${params.category}/pmu.json`);
|
||||||
|
const service = category.services.find(service => service.id === params.service);
|
||||||
|
|
||||||
|
if (!service) {
|
||||||
|
throw new Error(`Service not found: ${params.service}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const markdownData = parseMarkdownFile(`${params.category}/${params.service}/${params.service}.md`);
|
||||||
|
const post = { ...service, ...markdownData };
|
||||||
|
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
post,
|
||||||
|
og: {
|
||||||
|
title: post.title,
|
||||||
|
type: 'article',
|
||||||
|
image: post.image,
|
||||||
|
url: `${conf.url}/${params.category}/${params.service}`,
|
||||||
|
description: post.description,
|
||||||
|
published_time: post.frontmatter.date,
|
||||||
|
tags: post.frontmatter.tags
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue