[{"data":1,"prerenderedAt":614},["ShallowReactive",2],{"content-en-\u002Fapi\u002Floader":3},{"id":4,"title":5,"body":6,"description":607,"extension":608,"meta":609,"navigation":205,"path":610,"seo":611,"stem":612,"__hash__":613},"content_en\u002Fapi\u002Floader.md","Loader",{"type":7,"value":8,"toc":599},"minimark",[9,13,30,88,93,154,169,173,180,261,272,276,279,324,328,331,445,448,515,519,568,572,595],[10,11,5],"h1",{"id":12},"loader",[14,15,16,17,21,22,25,26,29],"p",{},"A loader resolves paths referenced by ",[18,19,20],"code",{},"include",", ",[18,23,24],{},"component",", and ",[18,27,28],{},"extend"," directives to source strings.",[31,32,37],"pre",{"className":33,"code":34,"language":35,"meta":36,"style":36},"language-ts shiki shiki-themes github-light github-dark","type Loader = (path: string) => Promise\u003Cstring>\n","ts","",[18,38,39],{"__ignoreMap":36},[40,41,44,48,52,55,59,63,66,70,73,76,79,82,85],"span",{"class":42,"line":43},"line",1,[40,45,47],{"class":46},"szBVR","type",[40,49,51],{"class":50},"sScJk"," Loader",[40,53,54],{"class":46}," =",[40,56,58],{"class":57},"sVt8B"," (",[40,60,62],{"class":61},"s4XuR","path",[40,64,65],{"class":46},":",[40,67,69],{"class":68},"sj4cs"," string",[40,71,72],{"class":57},") ",[40,74,75],{"class":46},"=>",[40,77,78],{"class":50}," Promise",[40,80,81],{"class":57},"\u003C",[40,83,84],{"class":68},"string",[40,86,87],{"class":57},">\n",[89,90,92],"h2",{"id":91},"when-you-need-one","When you need one",[94,95,96,112],"table",{},[97,98,99],"thead",{},[100,101,102,106,109],"tr",{},[103,104,105],"th",{},"Environment",[103,107,108],{},"Default",[103,110,111],{},"Requirement",[113,114,115,136],"tbody",{},[100,116,117,128,133],{},[118,119,120,121,21,124,127],"td",{},"Node (",[18,122,123],{},"renderServer",[18,125,126],{},"build",")",[118,129,130],{},[18,131,132],{},"createNodeLoader()",[118,134,135],{},"Optional — used automatically",[100,137,138,144,147],{},[118,139,140,141,127],{},"Browser (",[18,142,143],{},"renderClient",[118,145,146],{},"none",[118,148,149,153],{},[150,151,152],"strong",{},"Required"," — you provide the loader",[14,155,156,157,160,161,164,165,168],{},"Load failures throw ",[18,158,159],{},"HyogenError"," with code ",[18,162,163],{},"file_not_found"," or ",[18,166,167],{},"load_failed",".",[89,170,172],{"id":171},"createnodeloader","createNodeLoader",[14,174,175,176,179],{},"Full Node loader — local file system plus remote ",[18,177,178],{},"https:\u002F\u002F"," fetch.",[31,181,183],{"className":33,"code":182,"language":35,"meta":36,"style":36},"import { createNodeLoader } from '@b4moss\u002Fhyogen-md'\n\nconst loader = createNodeLoader({\n  from: '.\u002Fpage.md',       \u002F\u002F parent path for error messages\n  via: 'include',          \u002F\u002F 'include' | 'component' | 'extend'\n})\n",[18,184,185,200,207,224,240,255],{"__ignoreMap":36},[40,186,187,190,193,196],{"class":42,"line":43},[40,188,189],{"class":46},"import",[40,191,192],{"class":57}," { createNodeLoader } ",[40,194,195],{"class":46},"from",[40,197,199],{"class":198},"sZZnC"," '@b4moss\u002Fhyogen-md'\n",[40,201,203],{"class":42,"line":202},2,[40,204,206],{"emptyLinePlaceholder":205},true,"\n",[40,208,210,213,216,218,221],{"class":42,"line":209},3,[40,211,212],{"class":46},"const",[40,214,215],{"class":68}," loader",[40,217,54],{"class":46},[40,219,220],{"class":50}," createNodeLoader",[40,222,223],{"class":57},"({\n",[40,225,227,230,233,236],{"class":42,"line":226},4,[40,228,229],{"class":57},"  from: ",[40,231,232],{"class":198},"'.\u002Fpage.md'",[40,234,235],{"class":57},",       ",[40,237,239],{"class":238},"sJ8bj","\u002F\u002F parent path for error messages\n",[40,241,243,246,249,252],{"class":42,"line":242},5,[40,244,245],{"class":57},"  via: ",[40,247,248],{"class":198},"'include'",[40,250,251],{"class":57},",          ",[40,253,254],{"class":238},"\u002F\u002F 'include' | 'component' | 'extend'\n",[40,256,258],{"class":42,"line":257},6,[40,259,260],{"class":57},"})\n",[14,262,263,265,266,268,269,168],{},[18,264,123],{}," and ",[18,267,126],{}," use this by default when you omit ",[18,270,271],{},"options.loader",[89,273,275],{"id":274},"createfsloader","createFsLoader",[14,277,278],{},"File-system only — no remote fetch. Useful when you want to restrict loading to local paths.",[31,280,282],{"className":33,"code":281,"language":35,"meta":36,"style":36},"import { createFsLoader } from '@b4moss\u002Fhyogen-md'\n\nconst loader = createFsLoader({ from: '.\u002Fpage.md', via: 'component' })\n",[18,283,284,295,299],{"__ignoreMap":36},[40,285,286,288,291,293],{"class":42,"line":43},[40,287,189],{"class":46},[40,289,290],{"class":57}," { createFsLoader } ",[40,292,195],{"class":46},[40,294,199],{"class":198},[40,296,297],{"class":42,"line":202},[40,298,206],{"emptyLinePlaceholder":205},[40,300,301,303,305,307,310,313,315,318,321],{"class":42,"line":209},[40,302,212],{"class":46},[40,304,215],{"class":68},[40,306,54],{"class":46},[40,308,309],{"class":50}," createFsLoader",[40,311,312],{"class":57},"({ from: ",[40,314,232],{"class":198},[40,316,317],{"class":57},", via: ",[40,319,320],{"class":198},"'component'",[40,322,323],{"class":57}," })\n",[89,325,327],{"id":326},"custom-loader","Custom loader",[14,329,330],{},"Any async function that returns source text works:",[31,332,334],{"className":33,"code":333,"language":35,"meta":36,"style":36},"const loader: Loader = async (path) => {\n  if (path.startsWith('https:\u002F\u002F')) {\n    const res = await fetch(path)\n    return res.text()\n  }\n  return await readFile(path, 'utf8')\n}\n",[18,335,336,362,382,401,415,420,439],{"__ignoreMap":36},[40,337,338,340,342,344,346,348,351,353,355,357,359],{"class":42,"line":43},[40,339,212],{"class":46},[40,341,215],{"class":50},[40,343,65],{"class":46},[40,345,51],{"class":50},[40,347,54],{"class":46},[40,349,350],{"class":46}," async",[40,352,58],{"class":57},[40,354,62],{"class":61},[40,356,72],{"class":57},[40,358,75],{"class":46},[40,360,361],{"class":57}," {\n",[40,363,364,367,370,373,376,379],{"class":42,"line":202},[40,365,366],{"class":46},"  if",[40,368,369],{"class":57}," (path.",[40,371,372],{"class":50},"startsWith",[40,374,375],{"class":57},"(",[40,377,378],{"class":198},"'https:\u002F\u002F'",[40,380,381],{"class":57},")) {\n",[40,383,384,387,390,392,395,398],{"class":42,"line":209},[40,385,386],{"class":46},"    const",[40,388,389],{"class":68}," res",[40,391,54],{"class":46},[40,393,394],{"class":46}," await",[40,396,397],{"class":50}," fetch",[40,399,400],{"class":57},"(path)\n",[40,402,403,406,409,412],{"class":42,"line":226},[40,404,405],{"class":46},"    return",[40,407,408],{"class":57}," res.",[40,410,411],{"class":50},"text",[40,413,414],{"class":57},"()\n",[40,416,417],{"class":42,"line":242},[40,418,419],{"class":57},"  }\n",[40,421,422,425,427,430,433,436],{"class":42,"line":257},[40,423,424],{"class":46},"  return",[40,426,394],{"class":46},[40,428,429],{"class":50}," readFile",[40,431,432],{"class":57},"(path, ",[40,434,435],{"class":198},"'utf8'",[40,437,438],{"class":57},")\n",[40,440,442],{"class":42,"line":441},7,[40,443,444],{"class":57},"}\n",[14,446,447],{},"In the browser, map virtual paths to bundled or fetched content:",[31,449,451],{"className":33,"code":450,"language":35,"meta":36,"style":36},"const loader = async (path: string) => {\n  const mod = await import(`.\u002Ftemplates\u002F${path}?raw`)\n  return mod.default\n}\n",[18,452,453,477,504,511],{"__ignoreMap":36},[40,454,455,457,459,461,463,465,467,469,471,473,475],{"class":42,"line":43},[40,456,212],{"class":46},[40,458,215],{"class":50},[40,460,54],{"class":46},[40,462,350],{"class":46},[40,464,58],{"class":57},[40,466,62],{"class":61},[40,468,65],{"class":46},[40,470,69],{"class":68},[40,472,72],{"class":57},[40,474,75],{"class":46},[40,476,361],{"class":57},[40,478,479,482,485,487,489,492,494,497,499,502],{"class":42,"line":202},[40,480,481],{"class":46},"  const",[40,483,484],{"class":68}," mod",[40,486,54],{"class":46},[40,488,394],{"class":46},[40,490,491],{"class":46}," import",[40,493,375],{"class":57},[40,495,496],{"class":198},"`.\u002Ftemplates\u002F${",[40,498,62],{"class":57},[40,500,501],{"class":198},"}?raw`",[40,503,438],{"class":57},[40,505,506,508],{"class":42,"line":209},[40,507,424],{"class":46},[40,509,510],{"class":57}," mod.default\n",[40,512,513],{"class":42,"line":226},[40,514,444],{"class":57},[89,516,518],{"id":517},"isremotepath","isRemotePath",[31,520,522],{"className":33,"code":521,"language":35,"meta":36,"style":36},"import { isRemotePath } from '@b4moss\u002Fhyogen-md'\n\nisRemotePath('https:\u002F\u002Fexample.com\u002Fpartial.md') \u002F\u002F true\nisRemotePath('.\u002Fpartials\u002Fheader.md')           \u002F\u002F false\n",[18,523,524,535,539,553],{"__ignoreMap":36},[40,525,526,528,531,533],{"class":42,"line":43},[40,527,189],{"class":46},[40,529,530],{"class":57}," { isRemotePath } ",[40,532,195],{"class":46},[40,534,199],{"class":198},[40,536,537],{"class":42,"line":202},[40,538,206],{"emptyLinePlaceholder":205},[40,540,541,543,545,548,550],{"class":42,"line":209},[40,542,518],{"class":50},[40,544,375],{"class":57},[40,546,547],{"class":198},"'https:\u002F\u002Fexample.com\u002Fpartial.md'",[40,549,72],{"class":57},[40,551,552],{"class":238},"\u002F\u002F true\n",[40,554,555,557,559,562,565],{"class":42,"line":226},[40,556,518],{"class":50},[40,558,375],{"class":57},[40,560,561],{"class":198},"'.\u002Fpartials\u002Fheader.md'",[40,563,564],{"class":57},")           ",[40,566,567],{"class":238},"\u002F\u002F false\n",[89,569,571],{"id":570},"related","Related",[573,574,575,583,589],"ul",{},[576,577,578,582],"li",{},[579,580,143],"a",{"href":581},"\u002Fen\u002Fapi\u002Frender-client"," — loader is mandatory",[576,584,585],{},[579,586,588],{"href":587},"\u002Fen\u002Fsyntax\u002Fincludes","Includes and components",[576,590,591],{},[579,592,594],{"href":593},"\u002Fen\u002Fsyntax\u002Fpaths-and-security","Paths and security",[596,597,598],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":36,"searchDepth":202,"depth":202,"links":600},[601,602,603,604,605,606],{"id":91,"depth":202,"text":92},{"id":171,"depth":202,"text":172},{"id":274,"depth":202,"text":275},{"id":326,"depth":202,"text":327},{"id":517,"depth":202,"text":518},{"id":570,"depth":202,"text":571},"Resolve include, component, and extend paths to source text.","md",{},"\u002Fapi\u002Floader",{"title":5,"description":607},"api\u002Floader","IK9CIItya8eSw1SYd9hrM_lNkEKof6a7K75O7AV0MMA",1787223114633]