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
14 changes: 13 additions & 1 deletion cookbook/src/lib/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ export function mdQuote(text: string): MDQuote {
};
}

export type RawHTML = {
type: 'RAW_HTML';
html: string;
};

export function mdRawHTML(html: string): RawHTML {
return {type: 'RAW_HTML', html};
}

export type MDBlock =
| MDHeading
| MDImage
Expand All @@ -159,7 +168,8 @@ export type MDBlock =
| MDTable
| MDQuote
| MDFrontMatter
| MDNote;
| MDNote
| RawHTML;

export function renderMDBlock(block: MDBlock, format: RenderFormat): string {
switch (block.type) {
Expand Down Expand Up @@ -244,6 +254,8 @@ export function renderMDBlock(block: MDBlock, format: RenderFormat): string {
.map((line) => `> ${line}`)
.join('\n'),
].join('\n');
case 'RAW_HTML':
return block.html;
default:
assertNever(block);
}
Expand Down
27 changes: 26 additions & 1 deletion cookbook/src/lib/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
mdList,
mdNote,
mdParagraph,
mdRawHTML,
mdTable,
serializeMDBlocksToFile,
} from './markdown';
Expand Down Expand Up @@ -69,9 +70,11 @@ export function makeReadmeBlocks(
recipeName: string,
recipe: Recipe,
format: RenderFormat,
) {
): MDBlock[] {
const markdownTitle = makeTitle(recipeName, recipe, format);

const htmlCopyPromptTarget = makeCopyPromptTarget(recipe, recipeName, format);

const markdownDescription = mdParagraph(recipe.description);

const markdownNotes = maybeMDBlock(recipe.notes, (notes) =>
Expand Down Expand Up @@ -126,6 +129,7 @@ export function makeReadmeBlocks(

const blocks: MDBlock[] = [
markdownTitle,
...(htmlCopyPromptTarget != null ? [htmlCopyPromptTarget] : []),
markdownDescription,
...markdownNotes,
...markdownRequirements,
Expand Down Expand Up @@ -356,6 +360,8 @@ function makeTitle(
}

const HYDROGEN_REPO_BASE_URL = 'https://github.com/Shopify/hydrogen';
const HYDROGEN_REPO_RAW_BASE_URL =
'https://raw.githubusercontent.com/Shopify/hydrogen';

function hydrogenRepoFolderURL(params: {path: string; hash: string}): string {
const {path, hash} = params;
Expand All @@ -375,3 +381,22 @@ function hydrogenRepoRecipeBaseURL(params: {
function doNotEditComment(recipeName: string): string {
return `DO NOT EDIT. This file is generated from the shopify/hydrogen repo from this source file: \`cookbook/recipes/${recipeName}/recipe.yaml\``;
}

const copyPromptTargetClass = 'copy-prompt-target';

function makeCopyPromptTarget(
recipe: Recipe,
recipeName: string,
format: RenderFormat,
): MDBlock | null {
if (format !== 'shopify.dev') {
return null;
}

const dataURL = `${HYDROGEN_REPO_RAW_BASE_URL}/${recipe.commit}/cookbook/llms/${recipeName}.prompt.md`;
const dataInstructions = 'Follow this recipe to implement this feature.';

return mdRawHTML(
`<div class="${copyPromptTargetClass}" data-url="${dataURL}" data-instructions="${dataInstructions}"></div>`,
);
}