[{"data":1,"prerenderedAt":2367,"buildId":2368},["ShallowReactive",2],{"docs:\u002Fguide\u002Flayers":3},{"page":4,"section":17,"document":18,"credits":11,"prev":2363,"next":11},{"id":5,"path":6,"file":7,"title":8,"sourceTitle":9,"description":10,"tagline":10,"eyebrow":11,"credits":11,"keywords":12,"icon":13,"layout":14,"sidebar":15,"toc":15,"kind":11,"group":11,"navigation":15,"order":16},"layers","\u002Fguide\u002Flayers","guide\u002Flayers.md","Layers","Extend whoasks with layers","A layer is a plain object that adds a form, renders a form from your own source, changes the pick or sets the HTML to Markdown converter.",null,[],"i-lucide-layers","article",true,6,"guide",{"nodes":19,"toc":2348},[20,33,115,123,225,231,281,287,464,478,488,506,517,520,621,635,641,644,857,862,868,877,930,943,961,968,975,1106,1109,1115,1259,1265,1277,1446,1467,1483,1545,1556,1563,1624,1630,1665,1676,1682,1694,1971,1986,1993,1999,2005,2015,2185,2200,2203,2209],[21,22,23,24,28,29,32],"p",{},"A layer is a plain object. ",[25,26,27],"code",{},"whoasks(...layers)"," merges the layers it gets. An integration is a function that returns a layer, and the app passes its result to ",[25,30,31],{},"whoasks()",". There is no plugin type, no hook registry, and no lifecycle.",[34,35,38],"pre",{"language":36,"class":37,"wrap":15},"ts","shiki shiki-themes github-light-default github-dark-default dark:github-dark-default",[25,39,41,70,71,70,73,70,99],{"class":40},"language-ts",[42,43,46,50,54,57,60,63,67],"span",{"class":44,"style":45},"line","display: inline",[42,47,49],{"style":48},"color:#CF222E;--shiki-dark:#FF7B72","import",[42,51,53],{"style":52},"color:#1F2328;--shiki-dark:#E6EDF3"," { whoasks, ",[42,55,56],{"style":48},"type",[42,58,59],{"style":52}," Layer } ",[42,61,62],{"style":48},"from",[42,64,66],{"style":65},"color:#0A3069;--shiki-dark:#A5D6FF"," \"whoasks\"",[42,68,69],{"style":52},";","\n",[42,72],{"class":44,"style":45},[42,74,75,78,82,85,89,92,95],{"class":44,"style":45},[42,76,77],{"style":48},"const",[42,79,81],{"style":80},"color:#0550AE;--shiki-dark:#79C0FF"," layer",[42,83,84],{"style":48},":",[42,86,88],{"style":87},"color:#953800;--shiki-dark:#FFA657"," Layer",[42,90,91],{"style":48}," =",[42,93,94],{"style":52}," {}; ",[42,96,98],{"style":97},"color:#6E7781;--shiki-dark:#8B949E","\u002F\u002F every slot is optional",[42,100,101,103,106,108,112],{"class":44,"style":45},[42,102,77],{"style":48},[42,104,105],{"style":80}," site",[42,107,91],{"style":48},[42,109,111],{"style":110},"color:#8250DF;--shiki-dark:#D2A8FF"," whoasks",[42,113,114],{"style":52},"(layer);",[116,117,122],"h2",{"id":118,"anchor":119},"the-slots",{"label":120,"icon":121},"Section titled \"The slots\"","#","The slots",[124,125,126,142],"table",{},[127,128,129],"thead",{},[130,131,132,136,139],"tr",{},[133,134,135],"th",{},"Slot",[133,137,138],{},"Type",[133,140,141],{},"Answers",[143,144,145,161,176,191,206],"tbody",{},[130,146,147,153,158],{},[148,149,150],"td",{},[25,151,152],{},"forms",[148,154,155],{},[25,156,157],{},"Record\u003Cstring, Form>",[148,159,160],{},"What can a request ask for",[130,162,163,168,173],{},[148,164,165],{},[25,166,167],{},"render",[148,169,170],{},[25,171,172],{},"Record\u003Cstring, Render>",[148,174,175],{},"Who makes this form for this URL, without asking the converter",[130,177,178,183,188],{},[148,179,180],{},[25,181,182],{},"ask",[148,184,185],{},[25,186,187],{},"(ask, request) => change",[148,189,190],{},"Should the pick change, within what the request allowed",[130,192,193,198,203],{},[148,194,195],{},[25,196,197],{},"convert",[148,199,200],{},[25,201,202],{},"Convert | false",[148,204,205],{},"How HTML becomes Markdown",[130,207,208,213,218],{},[148,209,210],{},[25,211,212],{},"strict",[148,214,215],{},[25,216,217],{},"boolean",[148,219,220,221,224],{},"Should ",[25,222,223],{},"respond"," answer 406",[116,226,230],{"id":227,"anchor":228},"how-layers-merge",{"label":229,"icon":121},"Section titled \"How layers merge\"","How layers merge",[232,233,234,240,245,250,258],"ul",{},[235,236,237,239],"li",{},[25,238,152],{},": a later layer replaces a form with the same name, built-in forms included.",[235,241,242,244],{},[25,243,167],{},": each form keeps its renderers in layer order. The first one that returns a body wins.",[235,246,247,249],{},[25,248,182],{},": every hook runs, in layer order. Each sees the pick as the hooks before it left it.",[235,251,252,254,255,257],{},[25,253,197],{}," and ",[25,256,212],{},": the last layer that sets one wins.",[235,259,260,263,264,267,268,271,272,274,275,263,277,280],{},[25,261,262],{},"whoasks"," from ",[25,265,266],{},"\"whoasks\""," puts ",[25,269,270],{},"{ convert: mdream() }"," before your layers, so your ",[25,273,197],{}," replaces it. ",[25,276,262],{},[25,278,279],{},"\"whoasks\u002Fcore\""," starts with nothing.",[116,282,286],{"id":283,"anchor":284},"add-a-form",{"label":285,"icon":121},"Section titled \"Add a form\"","Add a form",[34,288,290],{"language":36,"filename":289,"class":37,"wrap":15},"yaml.ts",[25,291,292,70,308,70,310,70,330,70,347,70,352,70,354,70,367,70,369,70,407,70,420,70,431,70,454,70,459],{"class":40},[42,293,294,296,298,300,302,304,306],{"class":44,"style":45},[42,295,49],{"style":48},[42,297,53],{"style":52},[42,299,56],{"style":48},[42,301,59],{"style":52},[42,303,62],{"style":48},[42,305,66],{"style":65},[42,307,69],{"style":52},[42,309],{"class":44,"style":45},[42,311,312,315,318,321,323,325,327],{"class":44,"style":45},[42,313,314],{"style":48},"export",[42,316,317],{"style":48}," const",[42,319,320],{"style":80}," yaml",[42,322,84],{"style":48},[42,324,88],{"style":87},[42,326,91],{"style":48},[42,328,329],{"style":52}," {",[42,331,332,335,338,341,344],{"class":44,"style":45},[42,333,334],{"style":52},"  forms: { yaml: { types: [",[42,336,337],{"style":65},"\"application\u002Fyaml\"",[42,339,340],{"style":52},"], ext: ",[42,342,343],{"style":65},"\".yaml\"",[42,345,346],{"style":52}," } },",[42,348,349],{"class":44,"style":45},[42,350,351],{"style":52},"};",[42,353],{"class":44,"style":45},[42,355,356,358,360,362,364],{"class":44,"style":45},[42,357,77],{"style":48},[42,359,105],{"style":80},[42,361,91],{"style":48},[42,363,111],{"style":110},[42,365,366],{"style":52},"(yaml);",[42,368],{"class":44,"style":45},[42,370,371,373,376,379,382,385,387,390,393,395,398,401,404],{"class":44,"style":45},[42,372,314],{"style":48},[42,374,375],{"style":48}," function",[42,377,378],{"style":110}," route",[42,380,381],{"style":52},"(",[42,383,384],{"style":87},"request",[42,386,84],{"style":48},[42,388,389],{"style":87}," Request",[42,391,392],{"style":52},")",[42,394,84],{"style":48},[42,396,397],{"style":87}," Promise",[42,399,400],{"style":52},"\u003C",[42,402,403],{"style":87},"Response",[42,405,406],{"style":52},"> {",[42,408,409,412,415,417],{"class":44,"style":45},[42,410,411],{"style":48},"  return",[42,413,414],{"style":52}," site.",[42,416,223],{"style":110},[42,418,419],{"style":52},"(request, {",[42,421,422,425,428],{"class":44,"style":45},[42,423,424],{"style":52},"    json: { n: ",[42,426,427],{"style":80},"1",[42,429,430],{"style":52}," },",[42,432,433,436,439,442,445,448,451],{"class":44,"style":45},[42,434,435],{"style":110},"    yaml",[42,437,438],{"style":52},": () ",[42,440,441],{"style":48},"=>",[42,443,444],{"style":65}," \"n: 1",[42,446,447],{"style":48},"\\n",[42,449,450],{"style":65},"\"",[42,452,453],{"style":52},",",[42,455,456],{"class":44,"style":45},[42,457,458],{"style":52},"  });",[42,460,461],{"class":44,"style":45},[42,462,463],{"style":52},"}",[21,465,466,467,469,470,473,474,477],{},"The key in ",[25,468,152],{}," is the form's name. ",[25,471,472],{},"types"," are the media types that name it in ",[25,475,476],{},"Accept",". A wildcard or a URL override sends the first one.",[21,479,480,483,484,487],{},[25,481,482],{},"ext"," is optional. It makes a twin URL, and without its dot it is also a ",[25,485,486],{},"?format="," value.",[21,489,490,491,254,494,497,498,501,502,505],{},"On the route above, ",[25,492,493],{},"Accept: application\u002Fyaml",[25,495,496],{},"?format=yaml"," get ",[25,499,500],{},"application\u002Fyaml",". ",[25,503,504],{},"Accept: *\u002F*"," gets JSON, the first key.",[21,507,508,509,512,513,516],{},"whoasks does not serialize YAML. The value you give for ",[25,510,511],{},"yaml"," is a string. A form with a renderer is also offered on pages behind ",[25,514,515],{},"handle",", as shown in the next section.",[21,518,519],{},"You can also add a form for error responses:",[34,521,522],{"language":36,"class":37,"wrap":15},[25,523,524,70,539,70,550,70,554,70,556,70,561,70,572,70,577,70,606,70,616],{"class":40},[42,525,526,528,531,533,535,537],{"class":44,"style":45},[42,527,77],{"style":48},[42,529,530],{"style":80}," problem",[42,532,84],{"style":48},[42,534,88],{"style":87},[42,536,91],{"style":48},[42,538,329],{"style":52},[42,540,541,544,547],{"class":44,"style":45},[42,542,543],{"style":52},"  forms: { problem: { types: [",[42,545,546],{"style":65},"\"application\u002Fproblem+json\"",[42,548,549],{"style":52},"] } },",[42,551,552],{"class":44,"style":45},[42,553,351],{"style":52},[42,555],{"class":44,"style":45},[42,557,558],{"class":44,"style":45},[42,559,560],{"style":97},"\u002F\u002F In a route of whoasks(problem):",[42,562,563,566,568,570],{"class":44,"style":45},[42,564,565],{"style":48},"return",[42,567,414],{"style":52},[42,569,223],{"style":110},[42,571,381],{"style":52},[42,573,574],{"class":44,"style":45},[42,575,576],{"style":52},"  request,",[42,578,579,582,585,587,589,592,595,598,601,604],{"class":44,"style":45},[42,580,581],{"style":52},"  { problem: body, ",[42,583,584],{"style":110},"markdown",[42,586,438],{"style":52},[42,588,441],{"style":48},[42,590,591],{"style":65}," `failed validate. ${",[42,593,594],{"style":52},"body",[42,596,597],{"style":65},".",[42,599,600],{"style":52},"title",[42,602,603],{"style":65},"}`",[42,605,430],{"style":52},[42,607,608,611,614],{"class":44,"style":45},[42,609,610],{"style":52},"  { status: ",[42,612,613],{"style":80},"422",[42,615,430],{"style":52},[42,617,618],{"class":44,"style":45},[42,619,620],{"style":52},");",[21,622,623,624,627,628,631,632,597],{},"The object under ",[25,625,626],{},"problem"," goes through ",[25,629,630],{},"JSON.stringify"," and is sent as ",[25,633,634],{},"application\u002Fproblem+json",[116,636,640],{"id":637,"anchor":638},"render-a-form-from-your-own-source",{"label":639,"icon":121},"Section titled \"Render a form from your own source\"","Render a form from your own source",[21,642,643],{},"A content source knows the Markdown a page was written in. A renderer returns it, so that page is not converted from HTML.",[34,645,647],{"language":36,"filename":646,"class":37,"wrap":15},"content-layer.ts",[25,648,649,70,671,70,673,70,721,70,723,70,728,70,754,70,760,70,765,70,797,70,802,70,807,70,811,70,813,70,839,70,853],{"class":40},[42,650,651,653,655,657,660,662,665,667,669],{"class":44,"style":45},[42,652,49],{"style":48},[42,654,53],{"style":52},[42,656,56],{"style":48},[42,658,659],{"style":52}," Layer, ",[42,661,56],{"style":48},[42,663,664],{"style":52}," WhoAsks } ",[42,666,62],{"style":48},[42,668,66],{"style":65},[42,670,69],{"style":52},[42,672],{"class":44,"style":45},[42,674,675,677,680,682,685,688,690,693,696,698,700,703,705,707,709,712,715,718],{"class":44,"style":45},[42,676,56],{"style":48},[42,678,679],{"style":87}," Find",[42,681,91],{"style":48},[42,683,684],{"style":52}," (",[42,686,687],{"style":87},"path",[42,689,84],{"style":48},[42,691,692],{"style":80}," string",[42,694,695],{"style":52},") ",[42,697,441],{"style":48},[42,699,397],{"style":87},[42,701,702],{"style":52},"\u003C{ ",[42,704,584],{"style":87},[42,706,84],{"style":48},[42,708,692],{"style":80},[42,710,711],{"style":52}," } ",[42,713,714],{"style":48},"|",[42,716,717],{"style":80}," undefined",[42,719,720],{"style":52},">;",[42,722],{"class":44,"style":45},[42,724,725],{"class":44,"style":45},[42,726,727],{"style":97},"\u002F\u002F A content source answers for the pages it knows. Returning nothing lets the next renderer try.",[42,729,730,732,734,737,739,742,744,746,748,750,752],{"class":44,"style":45},[42,731,314],{"style":48},[42,733,375],{"style":48},[42,735,736],{"style":110}," contentMarkdown",[42,738,381],{"style":52},[42,740,741],{"style":87},"find",[42,743,84],{"style":48},[42,745,679],{"style":87},[42,747,392],{"style":52},[42,749,84],{"style":48},[42,751,88],{"style":87},[42,753,329],{"style":52},[42,755,756,758],{"class":44,"style":45},[42,757,411],{"style":48},[42,759,329],{"style":52},[42,761,762],{"class":44,"style":45},[42,763,764],{"style":52},"    render: {",[42,766,767,770,773,776,779,781,784,786,788,791,794],{"class":44,"style":45},[42,768,769],{"style":110},"      markdown",[42,771,772],{"style":52},": ",[42,774,775],{"style":48},"async",[42,777,778],{"style":52}," ({ ",[42,780,182],{"style":87},[42,782,783],{"style":52}," }) ",[42,785,441],{"style":48},[42,787,684],{"style":52},[42,789,790],{"style":48},"await",[42,792,793],{"style":110}," find",[42,795,796],{"style":52},"(ask.url.pathname))?.markdown,",[42,798,799],{"class":44,"style":45},[42,800,801],{"style":52},"    },",[42,803,804],{"class":44,"style":45},[42,805,806],{"style":52},"  };",[42,808,809],{"class":44,"style":45},[42,810,463],{"style":52},[42,812],{"class":44,"style":45},[42,814,815,817,819,822,824,826,828,830,832,834,837],{"class":44,"style":45},[42,816,314],{"style":48},[42,818,375],{"style":48},[42,820,821],{"style":110}," createSite",[42,823,381],{"style":52},[42,825,741],{"style":87},[42,827,84],{"style":48},[42,829,679],{"style":87},[42,831,392],{"style":52},[42,833,84],{"style":48},[42,835,836],{"style":87}," WhoAsks",[42,838,329],{"style":52},[42,840,841,843,845,847,850],{"class":44,"style":45},[42,842,411],{"style":48},[42,844,111],{"style":110},[42,846,381],{"style":52},[42,848,849],{"style":110},"contentMarkdown",[42,851,852],{"style":52},"(find));",[42,854,855],{"class":44,"style":45},[42,856,463],{"style":52},[21,858,859,861],{},[25,860,741],{}," stands for the source's own lookup. It is not a real ViteHub Content function. The layer lives in the content package, not in whoasks.",[21,863,864,865,867],{},"Pages that ",[25,866,741],{}," knows answer with their source Markdown. Every other page is still converted with mdream.",[21,869,870,871,873,874,84],{},"A renderer runs in ",[25,872,515],{}," only, for GET and HEAD, when the request picked its form. It receives ",[25,875,876],{},"{ request, ask, next }",[124,878,879,889],{},[127,880,881],{},[130,882,883,886],{},[133,884,885],{},"Field",[133,887,888],{},"What it is",[143,890,891,900,917],{},[130,892,893,897],{},[148,894,895],{},[25,896,384],{},[148,898,899],{},"The request as it arrived, twin URL included",[130,901,902,906],{},[148,903,904],{},[25,905,182],{},[148,907,908,909,912,913,916],{},"The pick. ",[25,910,911],{},"ask.url"," is the canonical URL, ",[25,914,915],{},"ask.type"," the media type to send",[130,918,919,924],{},[148,920,921],{},[25,922,923],{},"next()",[148,925,926,927,929],{},"The app's own response for ",[25,928,911],{},". The app runs once however many renderers call it, and each call returns a fresh copy",[21,931,932,933,935,936,254,939,942],{},"A renderer returns a string, a ",[25,934,403],{},", or nothing. ",[25,937,938],{},"null",[25,940,941],{},"undefined"," let the next renderer try, then the converter.",[21,944,945,946,949,950,952,953,955,956,263,959,597],{},"A string is sent with the picked type and ",[25,947,948],{},"Vary",". A ",[25,951,403],{}," is sent as it is, plus ",[25,954,948],{},", so set its ",[25,957,958],{},"Content-Type",[25,960,915],{},[21,962,963,964,967],{},"A form that has a renderer is offered on every page, after ",[25,965,966],{},"html"," and in layer order.",[969,970,974],"h3",{"id":971,"anchor":972},"use-the-apps-response",{"label":973,"icon":121},"Section titled \"Use the app's response\"","Use the app's response",[34,976,977],{"language":36,"class":37,"wrap":15},[25,978,979,70,1003,70,1009,70,1013,70,1037,70,1056,70,1075,70,1089,70,1094,70,1098,70,1102],{"class":40},[42,980,981,983,985,987,989,991,993,995,997,999,1001],{"class":44,"style":45},[42,982,314],{"style":48},[42,984,375],{"style":48},[42,986,736],{"style":110},[42,988,381],{"style":52},[42,990,741],{"style":87},[42,992,84],{"style":48},[42,994,679],{"style":87},[42,996,392],{"style":52},[42,998,84],{"style":48},[42,1000,88],{"style":87},[42,1002,329],{"style":52},[42,1004,1005,1007],{"class":44,"style":45},[42,1006,411],{"style":48},[42,1008,329],{"style":52},[42,1010,1011],{"class":44,"style":45},[42,1012,764],{"style":52},[42,1014,1015,1017,1019,1021,1023,1025,1028,1031,1033,1035],{"class":44,"style":45},[42,1016,769],{"style":110},[42,1018,772],{"style":52},[42,1020,775],{"style":48},[42,1022,778],{"style":52},[42,1024,182],{"style":87},[42,1026,1027],{"style":52},", ",[42,1029,1030],{"style":87},"next",[42,1032,783],{"style":52},[42,1034,441],{"style":48},[42,1036,329],{"style":52},[42,1038,1039,1042,1045,1047,1050,1053],{"class":44,"style":45},[42,1040,1041],{"style":48},"        const",[42,1043,1044],{"style":80}," page",[42,1046,91],{"style":48},[42,1048,1049],{"style":48}," await",[42,1051,1052],{"style":110}," next",[42,1054,1055],{"style":52},"();",[42,1057,1058,1061,1063,1066,1069,1071,1073],{"class":44,"style":45},[42,1059,1060],{"style":48},"        if",[42,1062,684],{"style":52},[42,1064,1065],{"style":48},"!",[42,1067,1068],{"style":52},"page.ok) ",[42,1070,565],{"style":48},[42,1072,717],{"style":80},[42,1074,69],{"style":52},[42,1076,1077,1080,1082,1084,1086],{"class":44,"style":45},[42,1078,1079],{"style":48},"        return",[42,1081,684],{"style":52},[42,1083,790],{"style":48},[42,1085,793],{"style":110},[42,1087,1088],{"style":52},"(ask.url.pathname))?.markdown;",[42,1090,1091],{"class":44,"style":45},[42,1092,1093],{"style":52},"      },",[42,1095,1096],{"class":44,"style":45},[42,1097,801],{"style":52},[42,1099,1100],{"class":44,"style":45},[42,1101,806],{"style":52},[42,1103,1104],{"class":44,"style":45},[42,1105,463],{"style":52},[21,1107,1108],{},"When the app answers 404 for the page, this renderer returns nothing, and the app's 404 page is converted and sent with its 404.",[969,1110,1114],{"id":1111,"anchor":1112},"return-a-response",{"label":1113,"icon":121},"Section titled \"Return a Response\"","Return a Response",[34,1116,1117],{"language":36,"class":37,"wrap":15},[25,1118,1119,70,1134,70,1139,70,1158,70,1175,70,1193,70,1207,70,1241,70,1246,70,1250,70,1255],{"class":40},[42,1120,1121,1123,1126,1128,1130,1132],{"class":44,"style":45},[42,1122,77],{"style":48},[42,1124,1125],{"style":80}," cached",[42,1127,84],{"style":48},[42,1129,88],{"style":87},[42,1131,91],{"style":48},[42,1133,329],{"style":52},[42,1135,1136],{"class":44,"style":45},[42,1137,1138],{"style":52},"  render: {",[42,1140,1141,1144,1146,1148,1150,1152,1154,1156],{"class":44,"style":45},[42,1142,1143],{"style":110},"    markdown",[42,1145,772],{"style":52},[42,1147,775],{"style":48},[42,1149,778],{"style":52},[42,1151,182],{"style":87},[42,1153,783],{"style":52},[42,1155,441],{"style":48},[42,1157,329],{"style":52},[42,1159,1160,1163,1166,1168,1170,1172],{"class":44,"style":45},[42,1161,1162],{"style":48},"      const",[42,1164,1165],{"style":80}," source",[42,1167,91],{"style":48},[42,1169,1049],{"style":48},[42,1171,793],{"style":110},[42,1173,1174],{"style":52},"(ask.url.pathname);",[42,1176,1177,1180,1182,1184,1187,1189,1191],{"class":44,"style":45},[42,1178,1179],{"style":48},"      if",[42,1181,684],{"style":52},[42,1183,1065],{"style":48},[42,1185,1186],{"style":52},"source) ",[42,1188,565],{"style":48},[42,1190,717],{"style":80},[42,1192,69],{"style":52},[42,1194,1195,1198,1201,1204],{"class":44,"style":45},[42,1196,1197],{"style":48},"      return",[42,1199,1200],{"style":48}," new",[42,1202,1203],{"style":110}," Response",[42,1205,1206],{"style":52},"(source.markdown, {",[42,1208,1209,1212,1215,1217,1220,1222,1224,1226,1229,1231,1234,1236,1239],{"class":44,"style":45},[42,1210,1211],{"style":52},"        headers: { ",[42,1213,1214],{"style":65},"\"content-type\"",[42,1216,772],{"style":52},[42,1218,1219],{"style":65},"`${",[42,1221,182],{"style":52},[42,1223,597],{"style":65},[42,1225,56],{"style":52},[42,1227,1228],{"style":65},"}; charset=utf-8`",[42,1230,1027],{"style":52},[42,1232,1233],{"style":65},"\"cache-control\"",[42,1235,772],{"style":52},[42,1237,1238],{"style":65},"\"max-age=300\"",[42,1240,430],{"style":52},[42,1242,1243],{"class":44,"style":45},[42,1244,1245],{"style":52},"      });",[42,1247,1248],{"class":44,"style":45},[42,1249,801],{"style":52},[42,1251,1252],{"class":44,"style":45},[42,1253,1254],{"style":52},"  },",[42,1256,1257],{"class":44,"style":45},[42,1258,351],{"style":52},[116,1260,1264],{"id":1261,"anchor":1262},"change-the-pick",{"label":1263,"icon":121},"Section titled \"Change the pick\"","Change the pick",[21,1266,1267,1268,1027,1271,1027,1273,1276],{},"A hook runs after the rules. It gets the pick and the request, and returns the part it wants to change: ",[25,1269,1270],{},"form",[25,1272,56],{},[25,1274,1275],{},"vary",", or nothing.",[34,1278,1280],{"language":36,"filename":1279,"class":37,"wrap":15},"codex.ts",[25,1281,1282,70,1298,70,1300,70,1305,70,1322,70,1338,70,1384,70,1423,70,1427,70,1431,70,1433],{"class":40},[42,1283,1284,1286,1288,1290,1292,1294,1296],{"class":44,"style":45},[42,1285,49],{"style":48},[42,1287,53],{"style":52},[42,1289,56],{"style":48},[42,1291,59],{"style":52},[42,1293,62],{"style":48},[42,1295,66],{"style":65},[42,1297,69],{"style":52},[42,1299],{"class":44,"style":45},[42,1301,1302],{"class":44,"style":45},[42,1303,1304],{"style":97},"\u002F\u002F Codex asks for Markdown with a browser-like Accept and rejects text\u002Fmarkdown. Send text\u002Fplain to it.",[42,1306,1307,1309,1311,1314,1316,1318,1320],{"class":44,"style":45},[42,1308,314],{"style":48},[42,1310,317],{"style":48},[42,1312,1313],{"style":80}," codexText",[42,1315,84],{"style":48},[42,1317,88],{"style":87},[42,1319,91],{"style":48},[42,1321,329],{"style":52},[42,1323,1324,1327,1329,1331,1333,1335],{"class":44,"style":45},[42,1325,1326],{"style":110},"  ask",[42,1328,381],{"style":52},[42,1330,182],{"style":87},[42,1332,1027],{"style":52},[42,1334,384],{"style":87},[42,1336,1337],{"style":52},") {",[42,1339,1340,1343,1346,1348,1351,1355,1358,1360,1363,1366,1369,1371,1374,1376,1379,1382],{"class":44,"style":45},[42,1341,1342],{"style":48},"    const",[42,1344,1345],{"style":80}," codex",[42,1347,91],{"style":48},[42,1349,1350],{"style":65}," \u002FChatGPT-User",[42,1352,1354],{"style":1353},"color:#116329;--shiki-light-font-weight:bold;--shiki-dark:#7EE787;--shiki-dark-font-weight:bold","\\\u002F",[42,1356,1357],{"style":65},"\u002F",[42,1359,597],{"style":52},[42,1361,1362],{"style":110},"test",[42,1364,1365],{"style":52},"(request.headers.",[42,1367,1368],{"style":110},"get",[42,1370,381],{"style":52},[42,1372,1373],{"style":65},"\"user-agent\"",[42,1375,695],{"style":52},[42,1377,1378],{"style":48},"??",[42,1380,1381],{"style":65}," \"\"",[42,1383,620],{"style":52},[42,1385,1386,1389,1392,1395,1398,1401,1404,1406,1408,1411,1414,1417,1420],{"class":44,"style":45},[42,1387,1388],{"style":48},"    if",[42,1390,1391],{"style":52}," (codex ",[42,1393,1394],{"style":48},"&&",[42,1396,1397],{"style":52}," ask.form ",[42,1399,1400],{"style":48},"===",[42,1402,1403],{"style":65}," \"markdown\"",[42,1405,695],{"style":52},[42,1407,565],{"style":48},[42,1409,1410],{"style":52}," { type: ",[42,1412,1413],{"style":65},"\"text\u002Fplain\"",[42,1415,1416],{"style":52},", vary: [",[42,1418,1419],{"style":65},"\"User-Agent\"",[42,1421,1422],{"style":52},"] };",[42,1424,1425],{"class":44,"style":45},[42,1426,1254],{"style":52},[42,1428,1429],{"class":44,"style":45},[42,1430,351],{"style":52},[42,1432],{"class":44,"style":45},[42,1434,1435,1437,1439,1441,1443],{"class":44,"style":45},[42,1436,77],{"style":48},[42,1438,105],{"style":80},[42,1440,91],{"style":48},[42,1442,111],{"style":110},[42,1444,1445],{"style":52},"(codexText);",[21,1447,1448,1449,1452,1453,1456,1457,501,1460,1463,1464,597],{},"With this layer, a ",[25,1450,1451],{},"ChatGPT-User"," request that picks Markdown gets it as ",[25,1454,1455],{},"text\u002Fplain; charset=utf-8",", with ",[25,1458,1459],{},"Vary: Accept, User-Agent",[25,1461,1462],{},"ask.reason"," becomes ",[25,1465,1466],{},"layer",[21,1468,1469,1470,1473,1474,1476,1477,1482],{},"It names ",[25,1471,1472],{},"User-Agent"," in ",[25,1475,1275],{}," so a cache keeps the two answers apart. See ",[1478,1479,1481],"a",{"href":1480},"\u002Fguide\u002Fnegotiation#codex-and-twin-urls","Codex and twin URLs"," for why.",[124,1484,1485,1495],{},[127,1486,1487],{},[130,1488,1489,1492],{},[133,1490,1491],{},"Returned",[133,1493,1494],{},"Kept when",[143,1496,1497,1509,1518,1528,1537],{},[130,1498,1499,1503],{},[148,1500,1501],{},[25,1502,1270],{},[148,1504,1505,1506,1508],{},"The form is offered and the request permits one of its types. After a twin or ",[25,1507,486],{},", only the forced form is offered",[130,1510,1511,1515],{},[148,1512,1513],{},[25,1514,56],{},[148,1516,1517],{},"It is one of the form's types and the request permits it",[130,1519,1520,1525],{},[148,1521,1522,1524],{},[25,1523,1270],{}," alone",[148,1526,1527],{},"The type is then chosen by rule 5",[130,1529,1530,1534],{},[148,1531,1532],{},[25,1533,1275],{},[148,1535,1536],{},"Always. The entries are appended",[130,1538,1539,1542],{},[148,1540,1541],{},"Nothing",[148,1543,1544],{},"The pick stays",[21,1546,1547,1548,1551,1552,1555],{},"A change the request did not allow is dropped, so a hook cannot send a type the client refused. With ",[25,1549,1550],{},"Accept: text\u002Fhtml, text\u002Fmarkdown;q=0",", a hook that returns ",[25,1553,1554],{},"{ form: \"markdown\" }"," changes nothing.",[21,1557,1558,1559,1562],{},"A hook that returns the pick it already has leaves ",[25,1560,1561],{},"reason"," alone. A hook that returns nothing is a place to log:",[34,1564,1565],{"language":36,"class":37,"wrap":15},[25,1566,1567,70,1582,70,1596,70,1616,70,1620],{"class":40},[42,1568,1569,1571,1574,1576,1578,1580],{"class":44,"style":45},[42,1570,77],{"style":48},[42,1572,1573],{"style":80}," log",[42,1575,84],{"style":48},[42,1577,88],{"style":87},[42,1579,91],{"style":48},[42,1581,329],{"style":52},[42,1583,1584,1586,1588,1590,1592,1594],{"class":44,"style":45},[42,1585,1326],{"style":110},[42,1587,381],{"style":52},[42,1589,182],{"style":87},[42,1591,1027],{"style":52},[42,1593,384],{"style":87},[42,1595,1337],{"style":52},[42,1597,1598,1601,1604,1607,1610,1613],{"class":44,"style":45},[42,1599,1600],{"style":52},"    console.",[42,1602,1603],{"style":110},"log",[42,1605,1606],{"style":52},"(ask.reason, ask.form, ",[42,1608,1609],{"style":48},"new",[42,1611,1612],{"style":110}," URL",[42,1614,1615],{"style":52},"(request.url).pathname);",[42,1617,1618],{"class":44,"style":45},[42,1619,1254],{"style":52},[42,1621,1622],{"class":44,"style":45},[42,1623,351],{"style":52},[116,1625,1629],{"id":1626,"anchor":1627},"set-the-converter-or-strict",{"label":1628,"icon":121},"Section titled \"Set the converter or strict\"","Set the converter or strict",[34,1631,1632],{"language":36,"class":37,"wrap":15},[25,1633,1634,70,1650],{"class":40},[42,1635,1636,1638,1641,1644,1647],{"class":44,"style":45},[42,1637,262],{"style":110},[42,1639,1640],{"style":52},"({ convert: ",[42,1642,1643],{"style":80},"false",[42,1645,1646],{"style":52}," }); ",[42,1648,1649],{"style":97},"\u002F\u002F no HTML to Markdown",[42,1651,1652,1654,1657,1660,1662],{"class":44,"style":45},[42,1653,262],{"style":110},[42,1655,1656],{"style":52},"({ strict: ",[42,1658,1659],{"style":80},"true",[42,1661,1646],{"style":52},[42,1663,1664],{"style":97},"\u002F\u002F 406 from respond",[21,1666,1667,1668,254,1672,597],{},"See ",[1478,1669,1671],{"href":1670},"\u002Fguide\u002Fpages#change-the-converter","Change the converter",[1478,1673,1675],{"href":1674},"\u002Fguide\u002Fapi-routes#refuse-with-406","Refuse with 406",[116,1677,1681],{"id":1678,"anchor":1679},"wrap-handle",{"label":1680,"icon":121},"Section titled \"Wrap handle\"","Wrap handle",[21,1683,1684,1686,1687,1689,1690,1693],{},[25,1685,515],{}," returns a ",[25,1688,403],{},", so a wrapper can add to it. ",[25,1691,1692],{},"site.ask(request)"," tells the wrapper what was picked.",[34,1695,1697],{"language":36,"filename":1696,"class":37,"wrap":15},"alternate.ts",[25,1698,1699,70,1712,70,1714,70,1726,70,1728,70,1733,70,1747,70,1758,70,1791,70,1805,70,1824,70,1840,70,1861,70,1873,70,1918,70,1934,70,1960,70,1967],{"class":40},[42,1700,1701,1703,1706,1708,1710],{"class":44,"style":45},[42,1702,49],{"style":48},[42,1704,1705],{"style":52}," { whoasks } ",[42,1707,62],{"style":48},[42,1709,66],{"style":65},[42,1711,69],{"style":52},[42,1713],{"class":44,"style":45},[42,1715,1716,1718,1720,1722,1724],{"class":44,"style":45},[42,1717,77],{"style":48},[42,1719,105],{"style":80},[42,1721,91],{"style":48},[42,1723,111],{"style":110},[42,1725,1055],{"style":52},[42,1727],{"class":44,"style":45},[42,1729,1730],{"class":44,"style":45},[42,1731,1732],{"style":97},"\u002F\u002F Tell people's browsers and crawlers where the Markdown twin is.",[42,1734,1735,1737,1740,1742,1745],{"class":44,"style":45},[42,1736,314],{"style":48},[42,1738,1739],{"style":48}," async",[42,1741,375],{"style":48},[42,1743,1744],{"style":110}," withAlternate",[42,1746,381],{"style":52},[42,1748,1749,1752,1754,1756],{"class":44,"style":45},[42,1750,1751],{"style":87},"  request",[42,1753,84],{"style":48},[42,1755,389],{"style":87},[42,1757,453],{"style":52},[42,1759,1760,1763,1765,1767,1769,1771,1773,1775,1777,1779,1782,1784,1786,1788],{"class":44,"style":45},[42,1761,1762],{"style":110},"  app",[42,1764,84],{"style":48},[42,1766,684],{"style":52},[42,1768,384],{"style":87},[42,1770,84],{"style":48},[42,1772,389],{"style":87},[42,1774,695],{"style":52},[42,1776,441],{"style":48},[42,1778,1203],{"style":87},[42,1780,1781],{"style":48}," |",[42,1783,397],{"style":87},[42,1785,400],{"style":52},[42,1787,403],{"style":87},[42,1789,1790],{"style":52},">,",[42,1792,1793,1795,1797,1799,1801,1803],{"class":44,"style":45},[42,1794,392],{"style":52},[42,1796,84],{"style":48},[42,1798,397],{"style":87},[42,1800,400],{"style":52},[42,1802,403],{"style":87},[42,1804,406],{"style":52},[42,1806,1807,1810,1813,1815,1817,1819,1821],{"class":44,"style":45},[42,1808,1809],{"style":48},"  const",[42,1811,1812],{"style":80}," response",[42,1814,91],{"style":48},[42,1816,1049],{"style":48},[42,1818,414],{"style":52},[42,1820,515],{"style":110},[42,1822,1823],{"style":52},"(request, app);",[42,1825,1826,1828,1831,1833,1835,1837],{"class":44,"style":45},[42,1827,1809],{"style":48},[42,1829,1830],{"style":80}," ask",[42,1832,91],{"style":48},[42,1834,414],{"style":52},[42,1836,182],{"style":110},[42,1838,1839],{"style":52},"(request);",[42,1841,1842,1845,1848,1851,1854,1856,1858],{"class":44,"style":45},[42,1843,1844],{"style":48},"  if",[42,1846,1847],{"style":52}," (ask.form ",[42,1849,1850],{"style":48},"!==",[42,1852,1853],{"style":65}," \"html\"",[42,1855,695],{"style":52},[42,1857,565],{"style":48},[42,1859,1860],{"style":52}," response;",[42,1862,1863,1865,1868,1870],{"class":44,"style":45},[42,1864,1809],{"style":48},[42,1866,1867],{"style":80}," path",[42,1869,91],{"style":48},[42,1871,1872],{"style":52}," ask.url.pathname;",[42,1874,1875,1877,1880,1882,1885,1888,1890,1893,1895,1898,1901,1903,1906,1909,1911,1913,1916],{"class":44,"style":45},[42,1876,1809],{"style":48},[42,1878,1879],{"style":80}," twin",[42,1881,91],{"style":48},[42,1883,1884],{"style":52}," path.",[42,1886,1887],{"style":110},"endsWith",[42,1889,381],{"style":52},[42,1891,1892],{"style":65},"\"\u002F\"",[42,1894,695],{"style":52},[42,1896,1897],{"style":48},"?",[42,1899,1900],{"style":65}," `${",[42,1902,687],{"style":52},[42,1904,1905],{"style":65},"}index.md`",[42,1907,1908],{"style":48}," :",[42,1910,1900],{"style":65},[42,1912,687],{"style":52},[42,1914,1915],{"style":65},"}.md`",[42,1917,69],{"style":52},[42,1919,1920,1922,1925,1927,1929,1931],{"class":44,"style":45},[42,1921,1809],{"style":48},[42,1923,1924],{"style":80}," copy",[42,1926,91],{"style":48},[42,1928,1200],{"style":48},[42,1930,1203],{"style":110},[42,1932,1933],{"style":52},"(response.body, response);",[42,1935,1936,1939,1942,1944,1947,1949,1952,1955,1958],{"class":44,"style":45},[42,1937,1938],{"style":52},"  copy.headers.",[42,1940,1941],{"style":110},"append",[42,1943,381],{"style":52},[42,1945,1946],{"style":65},"\"link\"",[42,1948,1027],{"style":52},[42,1950,1951],{"style":65},"`\u003C${",[42,1953,1954],{"style":52},"twin",[42,1956,1957],{"style":65},"}>; rel=\"alternate\"; type=\"text\u002Fmarkdown\"`",[42,1959,620],{"style":52},[42,1961,1962,1964],{"class":44,"style":45},[42,1963,411],{"style":48},[42,1965,1966],{"style":52}," copy;",[42,1968,1969],{"class":44,"style":45},[42,1970,463],{"style":52},[21,1972,1973,1976,1977,1980,1981,1976,1983,597],{},[25,1974,1975],{},"\u002Fdocs\u002Fguide"," gets ",[25,1978,1979],{},"Link: \u003C\u002Fdocs\u002Fguide.md>; rel=\"alternate\"; type=\"text\u002Fmarkdown\"",", and ",[25,1982,1357],{},[25,1984,1985],{},"\u003C\u002Findex.md>",[21,1987,1988,1989,1992],{},"A request that picked Markdown gets no ",[25,1990,1991],{},"Link"," header.",[21,1994,1995,1996,1998],{},"This wrapper adds the header to every response of a request that picked HTML, images included. Check the response's ",[25,1997,958],{}," if you want pages only.",[116,2000,2004],{"id":2001,"anchor":2002},"build-files-from-twins",{"label":2003,"icon":121},"Section titled \"Build files from twins\"","Build files from twins",[21,2006,2007,2008,2011,2012,2014],{},"A generator for ",[25,2009,2010],{},"llms.txt"," or a full-text file walks its own list of pages and asks ",[25,2013,515],{}," for each twin.",[34,2016,2018],{"language":36,"filename":2017,"class":37,"wrap":15},"build-llms.ts",[25,2019,2020,70,2034,70,2060,70,2080,70,2097,70,2134,70,2155,70,2159],{"class":40},[42,2021,2022,2024,2027,2029,2032],{"class":44,"style":45},[42,2023,77],{"style":48},[42,2025,2026],{"style":80}," origin",[42,2028,91],{"style":48},[42,2030,2031],{"style":65}," \"https:\u002F\u002Fexample.com\"",[42,2033,69],{"style":52},[42,2035,2036,2038,2041,2043,2046,2049,2051,2054,2057],{"class":44,"style":45},[42,2037,77],{"style":48},[42,2039,2040],{"style":80}," pages",[42,2042,91],{"style":48},[42,2044,2045],{"style":52}," [",[42,2047,2048],{"style":65},"\"\u002Fdocs\u002Fguide\"",[42,2050,1027],{"style":52},[42,2052,2053],{"style":65},"\"\u002Fdocs\u002Fapi\"",[42,2055,2056],{"style":52},"]; ",[42,2058,2059],{"style":97},"\u002F\u002F your own page list",[42,2061,2062,2064,2067,2069,2071,2074,2077],{"class":44,"style":45},[42,2063,77],{"style":48},[42,2065,2066],{"style":80}," parts",[42,2068,84],{"style":48},[42,2070,692],{"style":80},[42,2072,2073],{"style":52},"[] ",[42,2075,2076],{"style":48},"=",[42,2078,2079],{"style":52}," [];",[42,2081,2082,2085,2087,2089,2091,2094],{"class":44,"style":45},[42,2083,2084],{"style":48},"for",[42,2086,684],{"style":52},[42,2088,77],{"style":48},[42,2090,1867],{"style":80},[42,2092,2093],{"style":48}," of",[42,2095,2096],{"style":52}," pages) {",[42,2098,2099,2101,2103,2105,2107,2109,2111,2113,2115,2117,2120,2123,2126,2128,2131],{"class":44,"style":45},[42,2100,1809],{"style":48},[42,2102,1812],{"style":80},[42,2104,91],{"style":48},[42,2106,1049],{"style":48},[42,2108,414],{"style":52},[42,2110,515],{"style":110},[42,2112,381],{"style":52},[42,2114,1609],{"style":48},[42,2116,389],{"style":110},[42,2118,2119],{"style":52},"(origin ",[42,2121,2122],{"style":48},"+",[42,2124,2125],{"style":52}," path ",[42,2127,2122],{"style":48},[42,2129,2130],{"style":65}," \".md\"",[42,2132,2133],{"style":52},"), app);",[42,2135,2136,2139,2142,2144,2146,2149,2152],{"class":44,"style":45},[42,2137,2138],{"style":52},"  parts.",[42,2140,2141],{"style":110},"push",[42,2143,381],{"style":52},[42,2145,790],{"style":48},[42,2147,2148],{"style":52}," response.",[42,2150,2151],{"style":110},"text",[42,2153,2154],{"style":52},"());",[42,2156,2157],{"class":44,"style":45},[42,2158,463],{"style":52},[42,2160,2161,2163,2166,2168,2171,2174,2176,2178,2181,2183],{"class":44,"style":45},[42,2162,77],{"style":48},[42,2164,2165],{"style":80}," full",[42,2167,91],{"style":48},[42,2169,2170],{"style":52}," parts.",[42,2172,2173],{"style":110},"join",[42,2175,381],{"style":52},[42,2177,450],{"style":65},[42,2179,2180],{"style":48},"\\n\\n",[42,2182,450],{"style":65},[42,2184,620],{"style":52},[21,2186,2187,2190,2191,2194,2195,2197,2198,597],{},[25,2188,2189],{},"site"," is your site and ",[25,2192,2193],{},"app"," is the function you pass to ",[25,2196,515],{}," as ",[25,2199,1030],{},[21,2201,2202],{},"whoasks has no page list and writes no file. Serving the result is a normal route in your app.",[116,2204,2208],{"id":2205,"anchor":2206},"not-included",{"label":2207,"icon":121},"Section titled \"Not included\"","Not included",[124,2210,2211,2221],{},[127,2212,2213],{},[130,2214,2215,2218],{},[133,2216,2217],{},"Left out",[133,2219,2220],{},"How to build it",[143,2222,2223,2243,2259,2272,2284,2300,2326,2340],{},[130,2224,2225,2231],{},[148,2226,2227,2228],{},"Adapters for Hono, Next, SvelteKit, Astro, Node ",[25,2229,2230],{},"http",[148,2232,2233,2234,2237,2238,2242],{},"Each is ",[25,2235,2236],{},"site.handle(request, next)"," with that framework's request and next. ",[1478,2239,2241],{"href":2240},"\u002Fguide\u002Finstallation","Installation"," has Hono and Workers",[130,2244,2245,2248],{},[148,2246,2247],{},"A Nuxt module",[148,2249,2250,2251,2254,2255,2258],{},"A Nitro middleware from ",[25,2252,2253],{},"whoasks\u002Fh3",", plus a ",[25,2256,2257],{},"render.markdown"," layer from the content module",[130,2260,2261,2264],{},[148,2262,2263],{},"An agent text format, a size budget",[148,2265,2266,2267,2269,2270],{},"A ",[25,2268,584],{}," value passed to ",[25,2271,223],{},[130,2273,2274,2281],{},[148,2275,2276,1027,2278],{},[25,2277,2010],{},[25,2279,2280],{},"sitemap.md",[148,2282,2283],{},"A generator, as in the section above",[130,2285,2286,2289],{},[148,2287,2288],{},"A User-Agent registry",[148,2290,2291,2292,2295,2296,2299],{},"A hook, as in ",[1478,2293,1264],{"href":2294},"#change-the-pick",". It sets ",[25,2297,2298],{},"Vary: User-Agent"," itself",[130,2301,2302,2308],{},[148,2303,2304,2307],{},[25,2305,2306],{},"problem+json"," errors",[148,2309,2266,2310,1473,2313,2315,2316,2319,2320,2322,2323],{},[25,2311,2312],{},"status",[25,2314,223],{},"'s ",[25,2317,2318],{},"init",", or a ",[25,2321,626],{}," form, as in ",[1478,2324,286],{"href":2325},"#add-a-form",[130,2327,2328,2334],{},[148,2329,2330,2333],{},[25,2331,2332],{},"Link: rel=\"alternate\""," headers",[148,2335,2336,2337],{},"A wrapper, as in ",[1478,2338,1681],{"href":2339},"#wrap-handle",[130,2341,2342,2345],{},[148,2343,2344],{},"Web Bot Auth, Markdown lint, a CLI, redirects",[148,2346,2347],{},"Not planned",[2349,2351,2352,2353,2358,2359,2360,2361,2362],{"id":118,"depth":2350,"text":122},2,{"id":227,"depth":2350,"text":230},{"id":283,"depth":2350,"text":286},{"id":637,"depth":2350,"text":640,"children":2354},[2355,2357],{"id":971,"depth":2356,"text":974},3,{"id":1111,"depth":2356,"text":1114},{"id":1261,"depth":2350,"text":1264},{"id":1626,"depth":2350,"text":1629},{"id":1678,"depth":2350,"text":1681},{"id":2001,"depth":2350,"text":2004},{"id":2205,"depth":2350,"text":2208},{"path":2364,"title":2365,"description":2366},"\u002Fguide\u002Fnegotiation","Negotiation","The seven rules that pick a form from a twin URL, ?format= and Accept, and what Claude Code, Cursor, Codex and curl get from each.",1796579201910,"78c9ee36-381e-45a5-bdf8-02819f0a7eb0"]