Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,17 @@ NODE_ENV=development
# without it /feed still shows existing posts and accepts submissions)
OLOSTEP_API_KEY=

# Secret Vercel sends to the daily cron job (vercel.json). Generate: openssl rand -base64 32
# Secret the Worker's daily cron sends to /api/cron/linkedin-feed (worker.ts). Generate: openssl rand -base64 32
CRON_SECRET=

# Olostep searches per run, each costs credits (default 5)
# FEED_COLLECT_QUERIES=5

# -----------------------------------------------------------------------------
# Hosting (Cloudflare Workers)
# -----------------------------------------------------------------------------
# Database for the fellowship impact stories and survey
# IMPACT_MONGODB_URI

# Cloudflare account to deploy to with `npm run deploy` (local deploys only)
# CLOUDFLARE_ACCOUNT_ID
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,10 @@ coverage/

# Claude Code personal settings (local permission allowlists)
.claude/settings.local.json

# Cloudflare Workers (OpenNext build output, local secrets, generated bundle)
.open-next
.wrangler
.dev.vars*
!.dev.vars.example
lib/generated/
11 changes: 5 additions & 6 deletions app/agent-markdown/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'
import { NextRequest, NextResponse } from 'next/server'

import { htmlToMarkdown, pageFacts } from '@/lib/html-to-markdown'
import { SITE_NAME, SITE_URL } from '@/lib/seo'
import { readContent } from '@/lib/site-files'

/**
* The Markdown version of a public page, for AI agents. The middleware sends
Expand Down Expand Up @@ -47,9 +46,9 @@ function fromContentFile(sourcePath: string): string | undefined {
const match = sourcePath.match(/^\/(blog|guides)\/([a-z0-9-]+)$/)
if (!match) return undefined
const [, folder, slug] = match
const file = path.join(process.cwd(), 'content', folder, `${slug}.md`)
if (!fs.existsSync(file)) return undefined
const { data, content } = matter(fs.readFileSync(file, 'utf8'))
const raw = readContent(folder as 'blog' | 'guides', slug)
if (raw === undefined) return undefined
const { data, content } = matter(raw)
if (data.draft === true) return undefined
const head = frontMatter({ title: data.title, description: data.description, url: `${SITE_URL}${sourcePath}` })
return `${head}# ${data.title}\n\n${content.trim()}\n`
Expand All @@ -68,7 +67,7 @@ export async function GET(request: NextRequest) {
if (fromFile) return respond(fromFile)

// In production the page always comes from the public address, whatever host the request named
const origin = process.env.VERCEL_ENV === 'production' ? SITE_URL : request.nextUrl.origin
const origin = process.env.SITE_ENV === 'production' ? SITE_URL : request.nextUrl.origin
let html: string
try {
const page = await fetch(`${origin}${sourcePath}`, { headers: { Accept: 'text/html' }, redirect: 'follow', cache: 'no-store' })
Expand Down
5 changes: 3 additions & 2 deletions app/api/cron/linkedin-feed/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ export const dynamic = 'force-dynamic';
export const maxDuration = 300;

/**
* Daily Vercel cron (see vercel.json): discovers new public #DevWeekends LinkedIn
* posts through Olostep. Vercel sends `Authorization: Bearer $CRON_SECRET`.
* Daily cron (the Worker's scheduled handler, see worker.ts and wrangler.jsonc):
* discovers new public #DevWeekends LinkedIn posts through Olostep. The handler
* sends `Authorization: Bearer $CRON_SECRET`.
* Each search costs Olostep credits; FEED_COLLECT_QUERIES sets how many run.
*/
export async function GET(request: Request) {
Expand Down
26 changes: 7 additions & 19 deletions app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import fs from "fs";
import path from "path";
import matter from "gray-matter";
import type { Metadata } from "next";
import Image from "next/image";
import Link from "next/link";
import { ArticleBody } from "@/components/content/article-body";
import { formatDate } from "@/components/content/format-date";
import { Button, Eyebrow, container } from "@/components/site/page-kit";
import { contentSlugs, readContent } from "@/lib/site-files";
import { SITE_NAME, blogPostingJsonLd, breadcrumbJsonLd, excerptOf, jsonLdString, pageTitle, snippetOf, withSocial } from "@/lib/seo";

const backLink =
Expand All @@ -17,12 +16,7 @@ const backLink =
export const dynamicParams = false;

export function generateStaticParams() {
const dir = path.join(process.cwd(), "content", "blog");
if (!fs.existsSync(dir)) return [];
return fs
.readdirSync(dir)
.filter((f) => f.endsWith(".md"))
.map((f) => ({ slug: f.replace(/\.md$/, "") }));
return contentSlugs("blog").map((slug) => ({ slug }));
}

export async function generateMetadata({
Expand All @@ -31,9 +25,9 @@ export async function generateMetadata({
params: Promise<{ slug: string }>;
}): Promise<Metadata> {
const { slug } = await params;
const filePath = path.join(process.cwd(), "content", "blog", `${slug}.md`);
if (!fs.existsSync(filePath)) return { title: "Post not found", robots: { index: false } };
const { data, content } = matter(fs.readFileSync(filePath, "utf-8"));
const raw = readContent("blog", slug);
if (raw === undefined) return { title: "Post not found", robots: { index: false } };
const { data, content } = matter(raw);
const date = data.date ? new Date(data.date) : undefined;
const description = snippetOf(data.description) ?? excerptOf(content);
return withSocial({
Expand Down Expand Up @@ -62,14 +56,9 @@ export default async function BlogPost({
}) {
const { slug } = await params;

const filePath = path.join(
process.cwd(),
"content",
"blog",
`${slug}.md`
);
const fileContent = readContent("blog", slug);

if (!fs.existsSync(filePath)) {
if (fileContent === undefined) {
return (
<main className="bg-white">
<div className={`${container} py-24 md:py-32`}>
Expand All @@ -88,7 +77,6 @@ export default async function BlogPost({
);
}

const fileContent = fs.readFileSync(filePath, "utf-8");
const { data, content } = matter(fileContent);
const date = formatDate(data.date instanceof Date ? data.date.toISOString() : data.date);

Expand Down
9 changes: 2 additions & 7 deletions app/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from "fs";
import path from "path";
import matter from "gray-matter";
import BlogClient from "./blogClient";
import { withSocial } from "@/lib/seo";
import { contentSlugs, readContent } from "@/lib/site-files";

export const metadata = withSocial({
title: "News, guides and blog",
Expand Down Expand Up @@ -31,12 +30,8 @@ export type Post = {
const PORTRAIT_POSTER_SLUGS = new Set(["gsoc"]);

function readFolder(folder: "blog" | "guides") {
const dir = path.join(process.cwd(), "content", folder);
try {
return fs
.readdirSync(dir)
.filter((f) => f.endsWith(".md"))
.map((file) => ({ slug: file.replace(/\.md$/, ""), data: matter(fs.readFileSync(path.join(dir, file), "utf-8")).data }));
return contentSlugs(folder).map((slug) => ({ slug, data: matter(readContent(folder, slug) ?? "").data }));
} catch (error) {
console.error(`Could not read ${folder}:`, error);
return [];
Expand Down
16 changes: 4 additions & 12 deletions app/guides/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fs from "fs";
import path from "path";
import matter from "gray-matter";
import Link from "next/link";
import type { Metadata } from "next";
Expand All @@ -8,13 +6,11 @@ import { formatDate } from "@/components/content/format-date";
import { Button, Eyebrow, container } from "@/components/site/page-kit";
import { blogPostingJsonLd, breadcrumbJsonLd, jsonLdString, pageTitle, snippetOf, withSocial } from "@/lib/seo";
import { svgSize } from "@/lib/svg-size";

const guidesDir = path.join(process.cwd(), "content", "guides");
import { contentSlugs, readContent } from "@/lib/site-files";

function readGuide(slug: string) {
const filePath = path.join(guidesDir, `${slug}.md`);
if (!fs.existsSync(filePath)) return null;
const fileContent = fs.readFileSync(filePath, "utf-8");
const fileContent = readContent("guides", slug);
if (fileContent === undefined) return null;
return matter(fileContent);
}

Expand All @@ -23,11 +19,7 @@ function readGuide(slug: string) {
export const dynamicParams = false;

export function generateStaticParams() {
if (!fs.existsSync(guidesDir)) return [];
return fs
.readdirSync(guidesDir)
.filter((f) => f.endsWith(".md"))
.map((f) => ({ slug: f.replace(/\.md$/, "") }));
return contentSlugs("guides").map((slug) => ({ slug }));
}

export async function generateMetadata({
Expand Down
21 changes: 3 additions & 18 deletions app/guides/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from "fs";
import path from "path";
import matter from "gray-matter";
import GuidesClient from "./guidesClient";
import { withSocial } from "@/lib/seo";
import { contentSlugs, readContent } from "@/lib/site-files";

export const metadata = withSocial({
alternates: { canonical: "/guides" },
Expand Down Expand Up @@ -34,22 +33,8 @@ export const GUIDE_CATEGORIES = [
] as const;

export default function GuidesPage() {
const guidesDir = path.join(process.cwd(), "content", "guides");

let files: string[] = [];
try {
if (fs.existsSync(guidesDir)) {
files = fs.readdirSync(guidesDir).filter((f) => f.endsWith(".md"));
}
} catch (error) {
console.error("Could not read guides:", error);
}

const guides: Guide[] = files.map((file) => {
const filePath = path.join(guidesDir, file);
const fileContent = fs.readFileSync(filePath, "utf-8");
const { data } = matter(fileContent);
const slug = file.replace(/\.md$/, "");
const guides: Guide[] = contentSlugs("guides").map((slug) => {
const { data } = matter(readContent("guides", slug) ?? "");

return {
slug,
Expand Down
3 changes: 2 additions & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const gaId = process.env.NEXT_PUBLIC_GA_ID

// Cloudflare Web Analytics site token for devweekends.com. It is public (it ships
// in the page) and only counts on the live site, so previews and local runs stay out.
const cfBeaconToken = process.env.VERCEL_ENV === "production" ? "5206235d2175433195c5d83df73ba4fc" : undefined
// SITE_ENV is set to "production" only by `npm run deploy` (see package.json and wrangler.jsonc).
const cfBeaconToken = process.env.SITE_ENV === "production" ? "5206235d2175433195c5d83df73ba4fc" : undefined

export const metadata: Metadata = {
metadataBase: new URL(SITE_URL),
Expand Down
11 changes: 3 additions & 8 deletions app/llms-full.txt/route.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'
import { NextResponse } from 'next/server'

import { CONTENT_SIGNAL, SITE_URL } from '@/lib/seo'
import { contentSlugs, readContent } from '@/lib/site-files'

/** Posts or guides as Markdown links, newest first, with their own descriptions */
function contentLinks(folder: 'blog' | 'guides'): string {
const dir = path.join(process.cwd(), 'content', folder)
if (!fs.existsSync(dir)) return ''
return fs
.readdirSync(dir)
.filter((file) => file.endsWith('.md'))
.map((file) => ({ slug: file.replace(/\.md$/, ''), data: matter(fs.readFileSync(path.join(dir, file), 'utf8')).data }))
return contentSlugs(folder)
.map((slug) => ({ slug, data: matter(readContent(folder, slug) ?? '').data }))
.filter(({ data }) => data.draft !== true && data.title)
.sort((a, b) => new Date(b.data.date ?? 0).getTime() - new Date(a.data.date ?? 0).getTime())
.map(({ slug, data }) => `- [${data.title}](${SITE_URL}/${folder}/${slug})${data.description ? `: ${data.description}` : ''}`)
Expand Down
15 changes: 5 additions & 10 deletions app/rss.xml/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'

import { SITE_NAME, SITE_URL, excerptOf } from '@/lib/seo'
import { contentSlugs, readContent } from '@/lib/site-files'

// Built with the site, like the sitemap: posts and guides are read from the
// content folder, which is only there at build time.
Expand All @@ -11,19 +10,15 @@ export const dynamic = 'force-static'
type Item = { title: string; url: string; date?: Date; description?: string }

function items(folder: 'blog' | 'guides'): Item[] {
const dir = path.join(process.cwd(), 'content', folder)
if (!fs.existsSync(dir)) return []
return fs
.readdirSync(dir)
.filter((file) => file.endsWith('.md'))
.flatMap((file) => {
const { data, content } = matter(fs.readFileSync(path.join(dir, file), 'utf8'))
return contentSlugs(folder)
.flatMap((slug) => {
const { data, content } = matter(readContent(folder, slug) ?? '')
if (data.draft === true || !data.title) return []
const date = data.date ? new Date(data.date) : undefined
return [
{
title: String(data.title),
url: `${SITE_URL}/${folder}/${file.replace(/\.md$/, '')}`,
url: `${SITE_URL}/${folder}/${slug}`,
date: date && !Number.isNaN(date.getTime()) ? date : undefined,
description: data.description ?? excerptOf(content),
},
Expand Down
16 changes: 5 additions & 11 deletions app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'
import { MetadataRoute } from 'next'

import { listDsocProjects } from '@/lib/dsoc-projects'
import pageDates from '@/lib/page-dates.json'
import { SITE_URL } from '@/lib/seo'
import { contentSlugs, readContent } from '@/lib/site-files'

const baseUrl = SITE_URL

Expand Down Expand Up @@ -47,19 +46,14 @@ const pages: Entry[] = [

/** Blog posts and guides, each with its own publish date from its front matter */
function contentEntries(folder: 'blog' | 'guides', priority: number): MetadataRoute.Sitemap {
const dir = path.join(process.cwd(), 'content', folder)
if (!fs.existsSync(dir)) return []

return fs
.readdirSync(dir)
.filter((file) => file.endsWith('.md'))
.flatMap((file) => {
const { data } = matter(fs.readFileSync(path.join(dir, file), 'utf8'))
return contentSlugs(folder)
.flatMap((slug) => {
const { data } = matter(readContent(folder, slug) ?? '')
if (data.draft === true) return []
const date = data.date ? new Date(data.date) : undefined
return [
{
url: `${baseUrl}/${folder}/${file.replace(/\.md$/, '')}`,
url: `${baseUrl}/${folder}/${slug}`,
lastModified: date && !Number.isNaN(date.getTime()) ? date : undefined,
changeFrequency: 'monthly' as const,
priority,
Expand Down
Loading
Loading