mirror of
https://github.com/waynesutton/markdown-site.git
synced 2026-01-12 04:09:14 +00:00
v1.18.1 - CopyPageDropdown raw markdown URLs
- AI services (ChatGPT, Claude, Perplexity) now receive /raw/{slug}.md URLs
- Direct access to clean markdown content for better AI parsing
- No HTML parsing required by AI services
- Renamed buildUrlFromPageUrl to buildUrlFromRawMarkdown
v1.19.0 - Author display for posts and pages
- New optional authorName and authorImage frontmatter fields
- Round avatar image displayed next to date and read time
- Works on individual post and page views
- Write page updated with new field reference
v1.19.1 - GitHub Stars on Stats page
- Live star count from waynesutton/markdown-site repository
- Fetches from GitHub public API (no token required)
- Stats page now displays 6 cards with responsive grid
Documentation updates
- Frontmatter Flow section added to docs.md, setup-guide.md, files.md
- How frontmatter works with step-by-step processing flow
- Instructions for adding new frontmatter fields
Updated files:
- src/components/CopyPageDropdown.tsx
- src/pages/Stats.tsx
- src/pages/Post.tsx
- src/pages/Write.tsx
- src/styles/global.css
- convex/schema.ts
- convex/posts.ts
- convex/pages.ts
- scripts/sync-posts.ts
- content/blog/setup-guide.md
- content/pages/docs.md
- content/pages/changelog-page.md
- files.md
- README.md
- TASK.md
- changelog.md
- AGENTS.md
217 lines
5.7 KiB
TypeScript
217 lines
5.7 KiB
TypeScript
import { query, mutation } from "./_generated/server";
|
|
import { v } from "convex/values";
|
|
|
|
// Get all published pages for navigation
|
|
export const getAllPages = query({
|
|
args: {},
|
|
returns: v.array(
|
|
v.object({
|
|
_id: v.id("pages"),
|
|
slug: v.string(),
|
|
title: v.string(),
|
|
published: v.boolean(),
|
|
order: v.optional(v.number()),
|
|
excerpt: v.optional(v.string()),
|
|
image: v.optional(v.string()),
|
|
featured: v.optional(v.boolean()),
|
|
featuredOrder: v.optional(v.number()),
|
|
authorName: v.optional(v.string()),
|
|
authorImage: v.optional(v.string()),
|
|
}),
|
|
),
|
|
handler: async (ctx) => {
|
|
const pages = await ctx.db
|
|
.query("pages")
|
|
.withIndex("by_published", (q) => q.eq("published", true))
|
|
.collect();
|
|
|
|
// Sort by order (lower numbers first), then by title
|
|
const sortedPages = pages.sort((a, b) => {
|
|
const orderA = a.order ?? 999;
|
|
const orderB = b.order ?? 999;
|
|
if (orderA !== orderB) return orderA - orderB;
|
|
return a.title.localeCompare(b.title);
|
|
});
|
|
|
|
return sortedPages.map((page) => ({
|
|
_id: page._id,
|
|
slug: page.slug,
|
|
title: page.title,
|
|
published: page.published,
|
|
order: page.order,
|
|
excerpt: page.excerpt,
|
|
image: page.image,
|
|
featured: page.featured,
|
|
featuredOrder: page.featuredOrder,
|
|
authorName: page.authorName,
|
|
authorImage: page.authorImage,
|
|
}));
|
|
},
|
|
});
|
|
|
|
// Get featured pages for the homepage featured section
|
|
export const getFeaturedPages = query({
|
|
args: {},
|
|
returns: v.array(
|
|
v.object({
|
|
_id: v.id("pages"),
|
|
slug: v.string(),
|
|
title: v.string(),
|
|
excerpt: v.optional(v.string()),
|
|
image: v.optional(v.string()),
|
|
featuredOrder: v.optional(v.number()),
|
|
}),
|
|
),
|
|
handler: async (ctx) => {
|
|
const pages = await ctx.db
|
|
.query("pages")
|
|
.withIndex("by_featured", (q) => q.eq("featured", true))
|
|
.collect();
|
|
|
|
// Filter to only published pages and sort by featuredOrder
|
|
const featuredPages = pages
|
|
.filter((p) => p.published)
|
|
.sort((a, b) => {
|
|
const orderA = a.featuredOrder ?? 999;
|
|
const orderB = b.featuredOrder ?? 999;
|
|
return orderA - orderB;
|
|
});
|
|
|
|
return featuredPages.map((page) => ({
|
|
_id: page._id,
|
|
slug: page.slug,
|
|
title: page.title,
|
|
excerpt: page.excerpt,
|
|
image: page.image,
|
|
featuredOrder: page.featuredOrder,
|
|
}));
|
|
},
|
|
});
|
|
|
|
// Get a single page by slug
|
|
export const getPageBySlug = query({
|
|
args: {
|
|
slug: v.string(),
|
|
},
|
|
returns: v.union(
|
|
v.object({
|
|
_id: v.id("pages"),
|
|
slug: v.string(),
|
|
title: v.string(),
|
|
content: v.string(),
|
|
published: v.boolean(),
|
|
order: v.optional(v.number()),
|
|
excerpt: v.optional(v.string()),
|
|
image: v.optional(v.string()),
|
|
featured: v.optional(v.boolean()),
|
|
featuredOrder: v.optional(v.number()),
|
|
authorName: v.optional(v.string()),
|
|
authorImage: v.optional(v.string()),
|
|
}),
|
|
v.null(),
|
|
),
|
|
handler: async (ctx, args) => {
|
|
const page = await ctx.db
|
|
.query("pages")
|
|
.withIndex("by_slug", (q) => q.eq("slug", args.slug))
|
|
.first();
|
|
|
|
if (!page || !page.published) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
_id: page._id,
|
|
slug: page.slug,
|
|
title: page.title,
|
|
content: page.content,
|
|
published: page.published,
|
|
order: page.order,
|
|
excerpt: page.excerpt,
|
|
image: page.image,
|
|
featured: page.featured,
|
|
featuredOrder: page.featuredOrder,
|
|
authorName: page.authorName,
|
|
authorImage: page.authorImage,
|
|
};
|
|
},
|
|
});
|
|
|
|
// Public mutation for syncing pages from markdown files
|
|
export const syncPagesPublic = mutation({
|
|
args: {
|
|
pages: v.array(
|
|
v.object({
|
|
slug: v.string(),
|
|
title: v.string(),
|
|
content: v.string(),
|
|
published: v.boolean(),
|
|
order: v.optional(v.number()),
|
|
excerpt: v.optional(v.string()),
|
|
image: v.optional(v.string()),
|
|
featured: v.optional(v.boolean()),
|
|
featuredOrder: v.optional(v.number()),
|
|
authorName: v.optional(v.string()),
|
|
authorImage: v.optional(v.string()),
|
|
}),
|
|
),
|
|
},
|
|
returns: v.object({
|
|
created: v.number(),
|
|
updated: v.number(),
|
|
deleted: v.number(),
|
|
}),
|
|
handler: async (ctx, args) => {
|
|
let created = 0;
|
|
let updated = 0;
|
|
let deleted = 0;
|
|
|
|
const now = Date.now();
|
|
const incomingSlugs = new Set(args.pages.map((p) => p.slug));
|
|
|
|
// Get all existing pages
|
|
const existingPages = await ctx.db.query("pages").collect();
|
|
const existingBySlug = new Map(existingPages.map((p) => [p.slug, p]));
|
|
|
|
// Upsert incoming pages
|
|
for (const page of args.pages) {
|
|
const existing = existingBySlug.get(page.slug);
|
|
|
|
if (existing) {
|
|
// Update existing page
|
|
await ctx.db.patch(existing._id, {
|
|
title: page.title,
|
|
content: page.content,
|
|
published: page.published,
|
|
order: page.order,
|
|
excerpt: page.excerpt,
|
|
image: page.image,
|
|
featured: page.featured,
|
|
featuredOrder: page.featuredOrder,
|
|
authorName: page.authorName,
|
|
authorImage: page.authorImage,
|
|
lastSyncedAt: now,
|
|
});
|
|
updated++;
|
|
} else {
|
|
// Create new page
|
|
await ctx.db.insert("pages", {
|
|
...page,
|
|
lastSyncedAt: now,
|
|
});
|
|
created++;
|
|
}
|
|
}
|
|
|
|
// Delete pages that no longer exist in the repo
|
|
for (const existing of existingPages) {
|
|
if (!incomingSlugs.has(existing.slug)) {
|
|
await ctx.db.delete(existing._id);
|
|
deleted++;
|
|
}
|
|
}
|
|
|
|
return { created, updated, deleted };
|
|
},
|
|
});
|