diff --git a/app/md/proposal/[id]/route.ts b/app/md/proposal/[id]/route.ts new file mode 100644 index 000000000..a0135a99e --- /dev/null +++ b/app/md/proposal/[id]/route.ts @@ -0,0 +1,27 @@ +import { renderProposalMarkdown } from '@/lib/agent-markdown'; +import { PostService } from '@/services/post.service'; + +interface Params { + params: Promise<{ id: string }>; +} + +/** Markdown for a proposal. Reached by the Accept: text/markdown rewrite in next.config.js. */ +export async function GET(_request: Request, { params }: Params) { + const { id } = await params; + if (!/^\d+$/.test(id)) return new Response('Not found', { status: 404 }); + + try { + const work = await PostService.getPublic(id); + if (work.contentType !== 'preregistration' || work.isPublic === false) { + return new Response('Not found', { status: 404 }); + } + return new Response(renderProposalMarkdown(work, `/proposal/${id}/${work.slug}`), { + headers: { + 'Content-Type': 'text/markdown; charset=utf-8', + 'X-Robots-Tag': 'noindex', + }, + }); + } catch { + return new Response('Not found', { status: 404 }); + } +} diff --git a/app/md/rfp/[id]/route.ts b/app/md/rfp/[id]/route.ts new file mode 100644 index 000000000..40bedfed1 --- /dev/null +++ b/app/md/rfp/[id]/route.ts @@ -0,0 +1,27 @@ +import { renderRfpMarkdown } from '@/lib/agent-markdown'; +import { PostService } from '@/services/post.service'; + +interface Params { + params: Promise<{ id: string }>; +} + +/** Markdown for an RFP. Reached by the Accept: text/markdown rewrite in next.config.js. */ +export async function GET(_request: Request, { params }: Params) { + const { id } = await params; + if (!/^\d+$/.test(id)) return new Response('Not found', { status: 404 }); + + try { + const work = await PostService.getPublic(id); + if (work.contentType !== 'funding_request' || work.isPublic === false) { + return new Response('Not found', { status: 404 }); + } + return new Response(renderRfpMarkdown(work, `/rfp/${id}/${work.slug}`), { + headers: { + 'Content-Type': 'text/markdown; charset=utf-8', + 'X-Robots-Tag': 'noindex', + }, + }); + } catch { + return new Response('Not found', { status: 404 }); + } +} diff --git a/app/robots.ts b/app/robots.ts index e24763cd4..724cdae7e 100644 --- a/app/robots.ts +++ b/app/robots.ts @@ -19,6 +19,7 @@ export default function robots(): MetadataRoute.Robots { '/moderators/', '/expert-finder/', '/settings', + '/md/', '/_next/', '/sw.js', ], diff --git a/lib/agent-markdown.ts b/lib/agent-markdown.ts new file mode 100644 index 000000000..61037e2ad --- /dev/null +++ b/lib/agent-markdown.ts @@ -0,0 +1,59 @@ +import { SITE_CONFIG } from '@/lib/metadata'; +import { proposalGoal, storedGrantAmount } from '@/lib/metadata-helpers'; +import type { Work } from '@/types/work'; +import { stripHtml } from '@/utils/stringUtils'; + +function pageUrl(path: string): string { + return `${SITE_CONFIG.url}${path}`; +} + +function lines(rows: Array<[string, string | undefined]>): string { + return rows + .filter((row): row is [string, string] => Boolean(row[1])) + .map(([label, value]) => `- ${label}: ${value}`) + .join('\n'); +} + +function goalLabel(work: Work): string | undefined { + const goal = proposalGoal(work.fundraise, work.linkedGrant?.fundingMechanism); + return goal ? `${goal.value} ${goal.currency}` : undefined; +} + +function body(work: Work): string { + const text = stripHtml(work.previewContent || work.abstract || '').trim(); + return text ? `\n\n## Details\n\n${text}` : ''; +} + +/** Public RFP as markdown. Peer review text is never included. */ +export function renderRfpMarkdown(work: Work, path: string): string { + const grant = work.note?.post?.grant; + const amount = storedGrantAmount(grant?.amount, grant?.currency); + const amountLabel = amount ? `${amount.value} ${amount.currency}` : undefined; + const facts = lines([ + ['URL', pageUrl(path)], + ['Funder', grant?.organization || undefined], + ['Amount', amountLabel], + ['Status', grant?.status], + ['Application deadline', grant?.endDate || undefined], + ['Funding', grant?.fundingMechanism], + ]); + + return `# ${work.title}\n\n${facts}${body(work)}\n`; +} + +/** Public proposal as markdown. Peer review text is never included. */ +export function renderProposalMarkdown(work: Work, path: string): string { + const linked = work.linkedGrant; + const rfpUrl = linked?.postId ? pageUrl(`/rfp/${linked.postId}`) : undefined; + const facts = lines([ + ['URL', pageUrl(path)], + ['Funder', linked?.organization || undefined], + ['Request for Proposal', rfpUrl], + ['Goal', goalLabel(work)], + ['Status', work.fundraise?.status], + ['Funding deadline', work.fundraise?.endDate], + ['Funding', linked?.fundingMechanism], + ]); + + return `# ${work.title}\n\n${facts}${body(work)}\n`; +} diff --git a/lib/metadata-helpers.ts b/lib/metadata-helpers.ts index ef396e0d8..e8d85debe 100644 --- a/lib/metadata-helpers.ts +++ b/lib/metadata-helpers.ts @@ -2,8 +2,14 @@ import { buildArticleMetadata, buildDefaultOgImageUrl, buildOpenGraphMetadata, + SITE_CONFIG, } from '@/lib/metadata'; -import { generateDocumentStructuredData } from '@/lib/structured-data'; +import { + generateDocumentStructuredData, + generateGrantStructuredData, + generateProposalStructuredData, +} from '@/lib/structured-data'; +import type { Grant } from '@/types/grant'; import { Work } from '@/types/work'; import { stripHtml } from '@/utils/stringUtils'; @@ -21,6 +27,109 @@ export function getWorkShareImageUrl(work: Work): string { return getWorkImage(work) || buildDefaultOgImageUrl(work.title, getWorkDescription(work)); } +/** + * A community proposal's funding goal. Award applications publish a budget of 0 + * because the funder pays them directly, and a zero amount is not a goal. + */ +export function proposalGoal( + fundraise: Work['fundraise'], + fundingMechanism: string | undefined +): { value: number; currency: string } | undefined { + if (!fundraise || fundingMechanism === 'AWARD') return undefined; + const value = + fundraise.goalCurrency === 'USD' ? fundraise.goalAmount.usd : fundraise.goalAmount.rsc; + if (value <= 0) return undefined; + return { value, currency: fundraise.goalCurrency }; +} + +/** + * The grant's stored amount. `usd` is float(grant.amount); `rsc` is an exchange + * conversion of that number, so the published value stays `usd`. `currency` is + * the unit of the stored amount. + */ +export function storedGrantAmount( + amount: { usd: number } | undefined, + currency: string | undefined +): { value: number; currency: string } | undefined { + if (!amount || !currency) return undefined; + return { value: amount.usd, currency }; +} + +/** Proposals this grant has put money toward. Open applications with nothing raised are not funded yet. */ +function fundedGrantItems( + applications: Grant['applications'] +): Array<{ name: string; url: string }> { + return (applications ?? []).flatMap((application) => { + const raised = application.fundraise?.amountRaised; + const hasMoney = (raised?.usd ?? 0) > 0 || (raised?.rsc ?? 0) > 0; + const postId = application.preregistrationPostId; + const name = application.fundraise?.title; + if (!hasMoney || postId == null || !name) return []; + return [{ name, url: `${SITE_CONFIG.url}/proposal/${postId}` }]; + }); +} + +/** schema.org data for a work page: a grant, a proposal, a paper, or the generic article. */ +function buildWorkStructuredData(work: Work, url: string, description: string) { + const absoluteUrl = `${SITE_CONFIG.url}${url}`; + + if (work.contentType === 'funding_request') { + const grant = work.note?.post?.grant; + if (grant) { + return generateGrantStructuredData({ + title: work.title, + description: stripHtml(grant.description || ''), + url: absoluteUrl, + organization: grant.organization, + amount: storedGrantAmount(grant.amount, grant.currency), + status: grant.status, + endDate: grant.endDate, + fundingMechanism: grant.fundingMechanism, + image: work.image, + alternateName: + grant.shortTitle && grant.shortTitle !== work.title ? grant.shortTitle : undefined, + fundedItems: fundedGrantItems(grant.applications), + }); + } + } + + if (work.contentType === 'preregistration') { + const fundraise = work.fundraise; + return generateProposalStructuredData({ + title: work.title, + description, + url: absoluteUrl, + funder: work.linkedGrant?.organization || undefined, + goal: proposalGoal(fundraise, work.linkedGrant?.fundingMechanism), + status: fundraise?.status, + endDate: fundraise?.endDate, + fundingMechanism: work.linkedGrant?.fundingMechanism, + fundingName: work.linkedGrant?.shortTitle || work.linkedGrant?.title || undefined, + fundingUrl: work.linkedGrant?.postId + ? `${SITE_CONFIG.url}/rfp/${work.linkedGrant.postId}` + : undefined, + image: work.image, + members: work.authors + .filter((author) => author.authorProfile?.fullName) + .map((author) => ({ + name: author.authorProfile.fullName, + url: author.authorProfile.profileUrl + ? `${SITE_CONFIG.url}${author.authorProfile.profileUrl}` + : undefined, + })), + }); + } + + return generateDocumentStructuredData({ + ...work, + schemaType: work.contentType === 'paper' ? 'ScholarlyArticle' : undefined, + authors: work.authors?.map((a) => ({ + name: a.authorProfile?.fullName || '', + url: a.authorProfile?.profileUrl, + })), + }); +} + export function getWorkMetadata({ work, url, @@ -34,13 +143,7 @@ export function getWorkMetadata({ const description = getWorkDescription(work); const topics = work.contentType === 'paper' ? work.topics : undefined; - const structuredData = generateDocumentStructuredData({ - ...work, - authors: work.authors?.map((a) => ({ - name: a.authorProfile?.fullName || '', - url: a.authorProfile?.profileUrl, - })), - }); + const structuredData = buildWorkStructuredData(work, url, description); const articleMetadata = buildArticleMetadata({ title, diff --git a/lib/structured-data.ts b/lib/structured-data.ts index 0fd79f9b6..5ef483bac 100644 --- a/lib/structured-data.ts +++ b/lib/structured-data.ts @@ -18,6 +18,8 @@ interface Document { tags?: string[]; section?: string; type?: string; + /** schema.org type for the page, e.g. ScholarlyArticle. Defaults to Article. */ + schemaType?: string; } export function generateDocumentStructuredData(document: Document) { @@ -158,17 +160,157 @@ export function generateFAQStructuredData(items: Array<{ question: string; answe }; } +export interface GrantStructuredDataInput { + /** Full title. Unlike the article headline, this is not truncated. */ + title: string; + description?: string; + /** Absolute canonical URL of the RFP page. */ + url: string; + organization?: string; + amount?: { value: number; currency: string }; + /** Grant status, e.g. OPEN, CLOSED, COMPLETED. */ + status: string; + /** Application deadline, ISO 8601. */ + endDate?: string; + /** FUNDING is a community goal. AWARD is a pool the funder pays from directly. */ + fundingMechanism?: string; + /** Cover image. MonetaryGrant inherits image from Thing. */ + image?: string; + /** Short title, when it differs from the page title. */ + alternateName?: string; + /** Proposals this grant has already put money toward. */ + fundedItems?: Array<{ name: string; url: string }>; +} + +export interface ProposalStructuredDataInput { + title: string; + description?: string; + /** Absolute canonical URL of the proposal page. */ + url: string; + /** The RFP's funder, when the proposal applies to one. */ + funder?: string; + /** Funding goal in the goal's currency. */ + goal?: { value: number; currency: string }; + /** Fundraise status, e.g. OPEN, COMPLETED. */ + status?: string; + /** Fundraise deadline, ISO 8601. */ + endDate?: string; + /** FUNDING when the proposal sets a goal. AWARD when the funder pays it directly. */ + fundingMechanism?: string; + /** Title of the RFP this proposal applies to. */ + fundingName?: string; + /** Absolute URL of that RFP. */ + fundingUrl?: string; + /** Cover image. ResearchProject inherits image from Thing. */ + image?: string; + /** People on the project. ResearchProject has member, not author. */ + members?: Array<{ name: string; url?: string }>; +} + +/** + * schema.org ResearchProject for a proposal. The goal is what the project asks + * for. Amount raised is left out because it changes after the HTML is cached. + * Peer review content is never included here. + */ +export function generateProposalStructuredData(proposal: ProposalStructuredDataInput) { + const additionalProperty = [ + ...(proposal.fundingMechanism + ? [{ '@type': 'PropertyValue', name: 'fundingMechanism', value: proposal.fundingMechanism }] + : []), + ...(proposal.status + ? [{ '@type': 'PropertyValue', name: 'fundraiseStatus', value: proposal.status }] + : []), + ...(proposal.endDate + ? [{ '@type': 'PropertyValue', name: 'fundingDeadline', value: proposal.endDate }] + : []), + ]; + + const funding = + proposal.goal || proposal.fundingName || proposal.fundingUrl || proposal.funder + ? { + '@type': 'MonetaryGrant', + ...(proposal.fundingName && { name: proposal.fundingName }), + ...(proposal.fundingUrl && { url: proposal.fundingUrl }), + ...(proposal.funder && { + funder: { '@type': 'Organization', name: proposal.funder }, + }), + ...(proposal.goal && { + amount: { + '@type': 'MonetaryAmount', + currency: proposal.goal.currency, + value: proposal.goal.value, + }, + }), + } + : undefined; + + const members = proposal.members?.filter((member) => member.name) ?? []; + + return { + '@context': 'https://schema.org', + '@type': 'ResearchProject', + name: proposal.title, + ...(proposal.description && { description: proposal.description }), + url: proposal.url, + ...(proposal.image && { image: proposal.image }), + ...(proposal.funder && { + funder: { '@type': 'Organization', name: proposal.funder }, + }), + ...(funding && { funding }), + ...(members.length > 0 && { + member: members.map((member) => ({ + '@type': 'Person', + name: member.name, + ...(member.url && { url: member.url }), + })), + }), + ...(additionalProperty.length > 0 && { additionalProperty }), + }; +} + +/** + * schema.org MonetaryGrant for a public RFP. Schema.org has no deadline or + * status property on Grant, so those go in additionalProperty. + */ +export function generateGrantStructuredData(grant: GrantStructuredDataInput) { + return { + '@context': 'https://schema.org', + '@type': 'MonetaryGrant', + name: grant.title, + ...(grant.description && { description: grant.description }), + url: grant.url, + ...(grant.image && { image: grant.image }), + ...(grant.alternateName && { alternateName: grant.alternateName }), + ...(grant.organization && { + funder: { '@type': 'Organization', name: grant.organization }, + }), + ...(grant.amount && { + amount: { + '@type': 'MonetaryAmount', + currency: grant.amount.currency, + value: grant.amount.value, + }, + }), + ...(grant.fundedItems && + grant.fundedItems.length > 0 && { + fundedItem: grant.fundedItems.map((item) => ({ + '@type': 'ResearchProject', + name: item.name, + url: item.url, + })), + }), + additionalProperty: [ + { '@type': 'PropertyValue', name: 'status', value: grant.status }, + ...(grant.fundingMechanism + ? [{ '@type': 'PropertyValue', name: 'fundingMechanism', value: grant.fundingMechanism }] + : []), + ...(grant.endDate + ? [{ '@type': 'PropertyValue', name: 'applicationDeadline', value: grant.endDate }] + : []), + ], + }; +} + function getSchemaType(document: Document): string { - switch (document.type) { - case 'Paper': - return 'ScholarlyArticle'; - case 'Grant Proposal': - return 'Grant'; - case 'Proposal': - return 'CreativeWork'; - case 'Post': - return 'Article'; - default: - return 'Article'; - } + return document.schemaType ?? 'Article'; } diff --git a/next.config.js b/next.config.js index c197b2881..b03fc57e6 100644 --- a/next.config.js +++ b/next.config.js @@ -252,6 +252,28 @@ const nextConfig = { has: [MARKDOWN_ACCEPT], destination: '/llms.txt', }, + // The page and a markdown response cannot share a segment, so the same + // Accept header used for the homepage is rewritten to a route handler. + { + source: '/rfp/:id/:slug', + has: [MARKDOWN_ACCEPT], + destination: '/md/rfp/:id', + }, + { + source: '/rfp/:id(\\d+)', + has: [MARKDOWN_ACCEPT], + destination: '/md/rfp/:id', + }, + { + source: '/proposal/:id/:slug', + has: [MARKDOWN_ACCEPT], + destination: '/md/proposal/:id', + }, + { + source: '/proposal/:id(\\d+)', + has: [MARKDOWN_ACCEPT], + destination: '/md/proposal/:id', + }, ], // app/sitemap.ts uses generateSitemaps, which serves only /sitemap/.xml, // and Next still reserves app/sitemap.xml for it, so the index lives at @@ -278,6 +300,26 @@ const nextConfig = { has: [MARKDOWN_ACCEPT], headers: [{ key: 'Content-Type', value: 'text/markdown; charset=utf-8' }], }, + { + source: '/rfp/:id/:slug', + has: [MARKDOWN_ACCEPT], + headers: [{ key: 'Content-Type', value: 'text/markdown; charset=utf-8' }], + }, + { + source: '/rfp/:id(\\d+)', + has: [MARKDOWN_ACCEPT], + headers: [{ key: 'Content-Type', value: 'text/markdown; charset=utf-8' }], + }, + { + source: '/proposal/:id/:slug', + has: [MARKDOWN_ACCEPT], + headers: [{ key: 'Content-Type', value: 'text/markdown; charset=utf-8' }], + }, + { + source: '/proposal/:id(\\d+)', + has: [MARKDOWN_ACCEPT], + headers: [{ key: 'Content-Type', value: 'text/markdown; charset=utf-8' }], + }, // ARD (agenticresourcediscovery.org) requires the capability manifest to be // readable cross-origin. { @@ -310,6 +352,10 @@ const nextConfig = { }, ], }, + { + source: '/md/:path*', + headers: [{ key: 'X-Robots-Tag', value: 'noindex' }], + }, { // The OAuth consent page must never be framed or indexed source: '/oauth/authorize', diff --git a/public/.well-known/agent-skills/index.json b/public/.well-known/agent-skills/index.json index 253c87c45..4592bcd8a 100644 --- a/public/.well-known/agent-skills/index.json +++ b/public/.well-known/agent-skills/index.json @@ -6,7 +6,7 @@ "type": "skill-md", "description": "Find research funding opportunities, proposals, peer review bounties, and researcher profiles on ResearchHub.", "url": "/.well-known/agent-skills/navigate-researchhub/SKILL.md", - "digest": "sha256:7c827ee637979a7d395c0b4744bbccf1f1156324c97ccd1e4f8d5196409ffe80" + "digest": "sha256:88af19b7ffccf86e24784a05f1fba6b10f2afb8c6097969cabbf61ab7ed1c7f6" } ] } diff --git a/public/.well-known/agent-skills/navigate-researchhub/SKILL.md b/public/.well-known/agent-skills/navigate-researchhub/SKILL.md index a1f1fd036..e2d89fc51 100644 --- a/public/.well-known/agent-skills/navigate-researchhub/SKILL.md +++ b/public/.well-known/agent-skills/navigate-researchhub/SKILL.md @@ -19,7 +19,7 @@ ResearchHub is an open science platform where researchers publish, peer review, ## URL patterns - Proposals: `/proposal/{id}/{slug}` -- Grants: `/grant/{id}/{slug}` +- RFPs (grants): `/rfp/{id}/{slug}` - Posts: `/post/{id}/{slug}` - Authors: `/author/{id}` @@ -27,7 +27,8 @@ ResearchHub is an open science platform where researchers publish, peer review, - `https://researchhub.com/llms.txt`: site overview, also served for `Accept: text/markdown` requests to `/` - `https://researchhub.com/llms-full.txt`: extended site overview -- `https://researchhub.com/sitemap.xml`: public proposals and grants +- `https://researchhub.com/sitemap.xml`: static pages, public proposals (`/proposal/`), and RFPs (`/rfp/`). Papers and authors are not listed. +- RFP and proposal URLs return markdown when the request sends `Accept: text/markdown` - `https://researchhub.com/.well-known/api-catalog`: API catalog (RFC 9727) - `https://docs.researchhub.com/`: documentation diff --git a/public/ai.txt b/public/ai.txt index d61aaa81b..79556d034 100644 --- a/public/ai.txt +++ b/public/ai.txt @@ -1,6 +1,6 @@ # ai.txt — ResearchHub AI Policy # https://researchhub.com/ai.txt -# Last updated: 2026-08-17 +# Last updated: 2026-11-14 # This file states how AI systems may interact with public content # on researchhub.com. It is a policy declaration, not access control. @@ -22,6 +22,7 @@ Disallow: /moderators/ Disallow: /expert-finder/ Disallow: /settings Disallow: /_next/ +Disallow: /md/ Disallow: /sw.js # Licensing and AI/ML training policy diff --git a/public/llms.txt b/public/llms.txt index b378a77ed..03fbdee58 100644 --- a/public/llms.txt +++ b/public/llms.txt @@ -17,6 +17,8 @@ Dynamic content follows these URL patterns: authors at `/author/{id}`, posts at - [Requests for Proposals](https://researchhub.com/fund): Browse open funding opportunities and apply for research funding - [Proposals](https://researchhub.com/fund/proposals): Community research proposals seeking funding +- Each public RFP page includes MonetaryGrant structured data (amount, funder, deadline, status) +- RFP and proposal URLs return that page as markdown when the request sends `Accept: text/markdown` - [Endowment](https://researchhub.com/endowment): Hold RSC on the platform to earn Funding Credits — yield distributed daily that can only be spent on funding preregistered research proposals. No lockups, principal is always revocable. ## Peer Review & Publishing