[{"data":1,"prerenderedAt":2880},["ShallowReactive",2],{"series-\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fshowcase-your-github-projects-on-your-vitepress-blog":3,"series-context-\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch":2572},{"id":4,"title":5,"body":6,"contentId":2555,"date":2556,"description":2557,"extension":48,"github":2558,"meetTheInstructor":2560,"meta":2561,"navigation":273,"part":277,"path":2562,"rawbody":2563,"robots":2560,"schemaOrg":2560,"seo":2564,"seriesSlug":2565,"sitemap":2566,"stem":2570,"subtitle":2560,"topics":2560,"__hash__":2571},"series\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fshowcase-your-github-projects-on-your-vitepress-blog.md","Showcase Your GitHub Projects on Your VitePress Blog",{"type":7,"value":8,"toc":2548},"minimark",[9,26,31,43,102,120,152,166,328,338,349,353,360,367,414,440,445,517,524,538,560,566,574,786,793,867,870,1161,1164,1264,1269,1288,1302,1313,1318,1326,1342,1350,1491,1494,1498,1501,1514,1748,1758,1813,1822,1828,2152,2157,2512,2522,2530,2544],[10,11,12,13,17,18,21,22,25],"p",{},"In today's tutorial, we will extend our exploration of ",[14,15,16],"strong",{},"VitePress data loaders",", initiated in the episode on constructing a blog index page. This time, our focus will be on highlighting your ",[14,19,20],{},"GitHub projects"," by utilizing the ",[14,23,24],{},"GitHub API",". Exciting, isn't it?",[27,28,30],"h2",{"id":29},"crafting-a-new-page","Crafting a new page",[10,32,33,34,38,39,42],{},"As ever, a new page begins with a fresh Markdown file. Create a file entitled ",[35,36,37],"code",{},"projects.md"," in the ",[35,40,41],{},"src"," directory. This file, akin to the blog index page, will only contain frontmatter since the content will be dynamically loaded.",[44,45,50],"pre",{"className":46,"code":47,"filename":37,"language":48,"meta":49,"style":49},"language-md shiki shiki-themes github-light github-light github-dark","---\nlayout: projects\ntitle: Projects\ndescription: Explore my projects.\n---\n","md","",[35,51,52,61,75,86,97],{"__ignoreMap":49},[53,54,57],"span",{"class":55,"line":56},"line",1,[53,58,60],{"class":59},"sxrX7","---\n",[53,62,64,68,71],{"class":55,"line":63},2,[53,65,67],{"class":66},"sovSZ","layout",[53,69,70],{"class":59},": ",[53,72,74],{"class":73},"sIIMD","projects\n",[53,76,78,81,83],{"class":55,"line":77},3,[53,79,80],{"class":66},"title",[53,82,70],{"class":59},[53,84,85],{"class":73},"Projects\n",[53,87,89,92,94],{"class":55,"line":88},4,[53,90,91],{"class":66},"description",[53,93,70],{"class":59},[53,95,96],{"class":73},"Explore my projects.\n",[53,98,100],{"class":55,"line":99},5,[53,101,60],{"class":59},[10,103,104,105,108,109,38,112,115,116,119],{},"Next, we need to create the ",[14,106,107],{},"Vue component"," that will format our page. Insert a new file named ",[35,110,111],{},"ProjectsIndex.vue",[35,113,114],{},".vitepress\u002Ftheme\u002Fpages\u002FProjects"," directory. This component will resemble the ",[35,117,118],{},"BlogIndex.vue"," component:",[44,121,125],{"className":122,"code":123,"filename":118,"language":124,"meta":49,"style":49},"language-vue shiki shiki-themes github-light github-light github-dark","\u003Ctemplate>\n  projects\n\u003C\u002Ftemplate>\n","vue",[35,126,127,138,143],{"__ignoreMap":49},[53,128,129,132,135],{"class":55,"line":56},[53,130,131],{"class":59},"\u003C",[53,133,134],{"class":66},"template",[53,136,137],{"class":59},">\n",[53,139,140],{"class":55,"line":63},[53,141,142],{"class":59},"  projects\n",[53,144,145,148,150],{"class":55,"line":77},[53,146,147],{"class":59},"\u003C\u002F",[53,149,134],{"class":66},[53,151,137],{"class":59},[10,153,154,155,158,159,161,162,165],{},"Finally, link the newly created page to the layout ",[35,156,157],{},"projects"," specified in the ",[35,160,37],{}," file. To accomplish this, open the ",[35,163,164],{},"Layout.vue"," file and incorporate this page:",[44,167,169],{"className":122,"code":168,"filename":164,"language":124,"meta":49,"style":49},"\u003Ctemplate>\n  \u003Cdiv class=\"min-h-screen bg-[#FC88FF] py-16\">\n    \u003Cmain class=\"mx-auto max-w-screen-md\">\n      \u003CBlogIndex v-if=\"frontmatter.layout === 'blog'\" \u002F>\n      \u003CBlogShow v-else-if=\"frontmatter.layout === 'blog-show'\" \u002F>\n\n      \u003CProjectsIndex v-else-if=\"frontmatter.layout === 'projects'\" \u002F> \u002F\u002F [!code ++]\n    \u003C\u002Fmain>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n",[35,170,171,179,199,216,245,268,275,299,309,319],{"__ignoreMap":49},[53,172,173,175,177],{"class":55,"line":56},[53,174,131],{"class":59},[53,176,134],{"class":66},[53,178,137],{"class":59},[53,180,181,184,187,191,194,197],{"class":55,"line":63},[53,182,183],{"class":59},"  \u003C",[53,185,186],{"class":66},"div",[53,188,190],{"class":189},"snPdu"," class",[53,192,193],{"class":59},"=",[53,195,196],{"class":73},"\"min-h-screen bg-[#FC88FF] py-16\"",[53,198,137],{"class":59},[53,200,201,204,207,209,211,214],{"class":55,"line":77},[53,202,203],{"class":59},"    \u003C",[53,205,206],{"class":66},"main",[53,208,190],{"class":189},[53,210,193],{"class":59},[53,212,213],{"class":73},"\"mx-auto max-w-screen-md\"",[53,215,137],{"class":59},[53,217,218,221,224,228,230,233,236,239,242],{"class":55,"line":88},[53,219,220],{"class":59},"      \u003C",[53,222,223],{"class":66},"BlogIndex",[53,225,227],{"class":226},"s8jYJ"," v-if",[53,229,193],{"class":59},[53,231,232],{"class":73},"\"",[53,234,235],{"class":59},"frontmatter.layout ",[53,237,238],{"class":226},"===",[53,240,241],{"class":73}," 'blog'\"",[53,243,244],{"class":59}," \u002F>\n",[53,246,247,249,252,255,257,259,261,263,266],{"class":55,"line":99},[53,248,220],{"class":59},[53,250,251],{"class":66},"BlogShow",[53,253,254],{"class":226}," v-else-if",[53,256,193],{"class":59},[53,258,232],{"class":73},[53,260,235],{"class":59},[53,262,238],{"class":226},[53,264,265],{"class":73}," 'blog-show'\"",[53,267,244],{"class":59},[53,269,271],{"class":55,"line":270},6,[53,272,274],{"emptyLinePlaceholder":273},true,"\n",[53,276,278,280,283,285,287,289,291,293,296],{"class":55,"line":277},7,[53,279,220],{"class":59},[53,281,282],{"class":66},"ProjectsIndex",[53,284,254],{"class":226},[53,286,193],{"class":59},[53,288,232],{"class":73},[53,290,235],{"class":59},[53,292,238],{"class":226},[53,294,295],{"class":73}," 'projects'\"",[53,297,298],{"class":59}," \u002F> \u002F\u002F [!code ++]\n",[53,300,302,305,307],{"class":55,"line":301},8,[53,303,304],{"class":59},"    \u003C\u002F",[53,306,206],{"class":66},[53,308,137],{"class":59},[53,310,312,315,317],{"class":55,"line":311},9,[53,313,314],{"class":59},"  \u003C\u002F",[53,316,186],{"class":66},[53,318,137],{"class":59},[53,320,322,324,326],{"class":55,"line":321},10,[53,323,147],{"class":59},[53,325,134],{"class":66},[53,327,137],{"class":59},[10,329,330,331,337],{},"Navigate to ",[332,333,334],"a",{"href":334,"rel":335},"http:\u002F\u002Flocalhost:3000\u002Fprojects",[336],"nofollow"," to view the new page, which appears rather empty at the moment.",[339,340,341,346],"figure",{},[342,343],"img",{"alt":344,"src":345},"Our new empty projects page","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fshowcase-your-github-projects-on-your-vitepress-blog\u002Fvitepress-projects-empty.png",[347,348,344],"figcaption",{},[27,350,352],{"id":351},"retrieving-github-projects","Retrieving GitHub projects",[10,354,355,356,359],{},"Now, we need to retrieve data from ",[14,357,358],{},"GitHub"," to showcase on this page. We will use both the GitHub API for accessing up-to-date information and the VitePress data loaders to fetch data only during build time. Real-time data is unnecessary for this purpose.",[10,361,362,363,366],{},"First, establish a loader in ",[35,364,365],{},".vitepress\u002Fdata\u002Fgithub-projects.data.ts",":",[44,368,372],{"className":369,"code":370,"filename":365,"language":371,"meta":49,"style":49},"language-ts shiki shiki-themes github-light github-light github-dark","export default {\n  async load() {\n    return 'hello projects'\n  }\n}\n","ts",[35,373,374,385,396,404,409],{"__ignoreMap":49},[53,375,376,379,382],{"class":55,"line":56},[53,377,378],{"class":226},"export",[53,380,381],{"class":226}," default",[53,383,384],{"class":59}," {\n",[53,386,387,390,393],{"class":55,"line":63},[53,388,389],{"class":226},"  async",[53,391,392],{"class":189}," load",[53,394,395],{"class":59},"() {\n",[53,397,398,401],{"class":55,"line":77},[53,399,400],{"class":226},"    return",[53,402,403],{"class":73}," 'hello projects'\n",[53,405,406],{"class":55,"line":88},[53,407,408],{"class":59},"  }\n",[53,410,411],{"class":55,"line":99},[53,412,413],{"class":59},"}\n",[10,415,416,417,420,421,424,425,433,434,439],{},"Remember that the ",[35,418,419],{},".data.ts"," extension is essential to notify ",[14,422,423],{},"VitePress"," that this file functions as a data loader. VitePress uses a Vite plugin to ",[332,426,429,430,432],{"href":427,"rel":428},"https:\u002F\u002Fgithub.com\u002Fvuejs\u002Fvitepress\u002Fblob\u002Fmain\u002Fsrc\u002Fnode\u002Fplugins\u002FstaticDataPlugin.ts#L11",[336],"detect imports from a ",[35,431,419],{}," file",". Upon detection, data loading occurs, returning only the results to the client. Consequently, data is transformed during build time, offering immediate browser availability, akin to ",[332,435,438],{"href":436,"rel":437},"https:\u002F\u002Fvite.dev\u002Fguide\u002Fapi-plugin#virtual-modules-convention",[336],"virtual modules in Vite",", yet more tailored to VitePress' needs.",[10,441,442,443,119],{},"Then, load this file in the ",[35,444,111],{},[44,446,448],{"className":122,"code":447,"filename":111,"language":124,"meta":49,"style":49},"\u003Cscript lang=\"ts\" setup>\nimport { data } from '..\u002F..\u002F..\u002Fdata\u002Fgithub-projects.data'\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  {{ data }}\n\u003C\u002Ftemplate>\n",[35,449,450,470,484,492,496,504,509],{"__ignoreMap":49},[53,451,452,454,457,460,462,465,468],{"class":55,"line":56},[53,453,131],{"class":59},[53,455,456],{"class":66},"script",[53,458,459],{"class":189}," lang",[53,461,193],{"class":59},[53,463,464],{"class":73},"\"ts\"",[53,466,467],{"class":189}," setup",[53,469,137],{"class":59},[53,471,472,475,478,481],{"class":55,"line":63},[53,473,474],{"class":226},"import",[53,476,477],{"class":59}," { data } ",[53,479,480],{"class":226},"from",[53,482,483],{"class":73}," '..\u002F..\u002F..\u002Fdata\u002Fgithub-projects.data'\n",[53,485,486,488,490],{"class":55,"line":77},[53,487,147],{"class":59},[53,489,456],{"class":66},[53,491,137],{"class":59},[53,493,494],{"class":55,"line":88},[53,495,274],{"emptyLinePlaceholder":273},[53,497,498,500,502],{"class":55,"line":99},[53,499,131],{"class":59},[53,501,134],{"class":66},[53,503,137],{"class":59},[53,505,506],{"class":55,"line":270},[53,507,508],{"class":59},"  {{ data }}\n",[53,510,511,513,515],{"class":55,"line":277},[53,512,147],{"class":59},[53,514,134],{"class":66},[53,516,137],{"class":59},[10,518,519,520,523],{},"Our page now displays the text ",[35,521,522],{},"hello projects",". It's a promising beginning!",[10,525,526,527,529,530,533,534,537],{},"With this setup, we can now retrieve the ",[14,528,20],{}," data. Return to our ",[35,531,532],{},"github-projects.data.ts"," file and fetch data from the GitHub API. To facilitate this, we will install the ",[35,535,536],{},"octokit"," package:",[44,539,543],{"className":540,"code":541,"filename":532,"language":542,"meta":49,"style":49},"language-bash shiki shiki-themes github-light github-light github-dark","pnpm add -D octokit\n","bash",[35,544,545],{"__ignoreMap":49},[53,546,547,550,553,557],{"class":55,"line":56},[53,548,549],{"class":189},"pnpm",[53,551,552],{"class":73}," add",[53,554,556],{"class":555},"sBjJW"," -D",[53,558,559],{"class":73}," octokit\n",[10,561,562,563,565],{},"Then, edit the ",[35,564,532],{}," file. To ease future modifications, let's create an array organizing all our projects into categories.",[567,568,571],"callout",{"color":569,"icon":570},"info","i-ph-info-duotone",[10,572,573],{},"This is an example, but remember that you can structure the data as you prefer.",[44,575,577],{"className":369,"code":576,"filename":532,"language":371,"meta":49,"style":49},"export default {\n  async load() {\n    const projects = [\n      {\n        title: 'Website',\n        projects: ['barbapapazes\u002Forion'],\n      },\n      {\n        title: 'Nuxt Modules',\n        projects: [\n          'barbapapazes\u002Fnuxt-authorization',\n          'barbapapazes\u002Fnuxt-payload-analyzer',\n        ],\n      },\n      {\n        title: 'Nuxt Templates',\n        projects: [\n          'barbapapazes\u002Fgavarnie',\n          'barbapapazes\u002Fslantire',\n          'barbapapazes\u002Fthe-green-chronicle',\n        ],\n      },\n      {\n        title: 'Tools',\n        projects: ['barbapapazes\u002Futils-ai'],\n      },\n    ]\n  }\n}\n",[35,578,579,587,595,609,614,625,636,641,645,654,659,667,675,681,686,691,701,706,714,722,730,735,740,745,755,765,770,776,781],{"__ignoreMap":49},[53,580,581,583,585],{"class":55,"line":56},[53,582,378],{"class":226},[53,584,381],{"class":226},[53,586,384],{"class":59},[53,588,589,591,593],{"class":55,"line":63},[53,590,389],{"class":226},[53,592,392],{"class":189},[53,594,395],{"class":59},[53,596,597,600,603,606],{"class":55,"line":77},[53,598,599],{"class":226},"    const",[53,601,602],{"class":555}," projects",[53,604,605],{"class":226}," =",[53,607,608],{"class":59}," [\n",[53,610,611],{"class":55,"line":88},[53,612,613],{"class":59},"      {\n",[53,615,616,619,622],{"class":55,"line":99},[53,617,618],{"class":59},"        title: ",[53,620,621],{"class":73},"'Website'",[53,623,624],{"class":59},",\n",[53,626,627,630,633],{"class":55,"line":270},[53,628,629],{"class":59},"        projects: [",[53,631,632],{"class":73},"'barbapapazes\u002Forion'",[53,634,635],{"class":59},"],\n",[53,637,638],{"class":55,"line":277},[53,639,640],{"class":59},"      },\n",[53,642,643],{"class":55,"line":301},[53,644,613],{"class":59},[53,646,647,649,652],{"class":55,"line":311},[53,648,618],{"class":59},[53,650,651],{"class":73},"'Nuxt Modules'",[53,653,624],{"class":59},[53,655,656],{"class":55,"line":321},[53,657,658],{"class":59},"        projects: [\n",[53,660,662,665],{"class":55,"line":661},11,[53,663,664],{"class":73},"          'barbapapazes\u002Fnuxt-authorization'",[53,666,624],{"class":59},[53,668,670,673],{"class":55,"line":669},12,[53,671,672],{"class":73},"          'barbapapazes\u002Fnuxt-payload-analyzer'",[53,674,624],{"class":59},[53,676,678],{"class":55,"line":677},13,[53,679,680],{"class":59},"        ],\n",[53,682,684],{"class":55,"line":683},14,[53,685,640],{"class":59},[53,687,689],{"class":55,"line":688},15,[53,690,613],{"class":59},[53,692,694,696,699],{"class":55,"line":693},16,[53,695,618],{"class":59},[53,697,698],{"class":73},"'Nuxt Templates'",[53,700,624],{"class":59},[53,702,704],{"class":55,"line":703},17,[53,705,658],{"class":59},[53,707,709,712],{"class":55,"line":708},18,[53,710,711],{"class":73},"          'barbapapazes\u002Fgavarnie'",[53,713,624],{"class":59},[53,715,717,720],{"class":55,"line":716},19,[53,718,719],{"class":73},"          'barbapapazes\u002Fslantire'",[53,721,624],{"class":59},[53,723,725,728],{"class":55,"line":724},20,[53,726,727],{"class":73},"          'barbapapazes\u002Fthe-green-chronicle'",[53,729,624],{"class":59},[53,731,733],{"class":55,"line":732},21,[53,734,680],{"class":59},[53,736,738],{"class":55,"line":737},22,[53,739,640],{"class":59},[53,741,743],{"class":55,"line":742},23,[53,744,613],{"class":59},[53,746,748,750,753],{"class":55,"line":747},24,[53,749,618],{"class":59},[53,751,752],{"class":73},"'Tools'",[53,754,624],{"class":59},[53,756,758,760,763],{"class":55,"line":757},25,[53,759,629],{"class":59},[53,761,762],{"class":73},"'barbapapazes\u002Futils-ai'",[53,764,635],{"class":59},[53,766,768],{"class":55,"line":767},26,[53,769,640],{"class":59},[53,771,773],{"class":55,"line":772},27,[53,774,775],{"class":59},"    ]\n",[53,777,779],{"class":55,"line":778},28,[53,780,408],{"class":59},[53,782,784],{"class":55,"line":783},29,[53,785,413],{"class":59},[10,787,788,789,792],{},"Next, create an ",[14,790,791],{},"Octokit"," instance for fetching data:",[44,794,797],{"className":369,"code":795,"filename":796,"language":371,"meta":49,"style":49},"import { Octokit } from 'octokit'\n\nexport default {\n  async load() {\n    \u002F\u002F ...\n\n    const octokit = new Octokit()\n  }\n}\n","Example",[35,798,799,811,815,823,831,837,841,859,863],{"__ignoreMap":49},[53,800,801,803,806,808],{"class":55,"line":56},[53,802,474],{"class":226},[53,804,805],{"class":59}," { Octokit } ",[53,807,480],{"class":226},[53,809,810],{"class":73}," 'octokit'\n",[53,812,813],{"class":55,"line":63},[53,814,274],{"emptyLinePlaceholder":273},[53,816,817,819,821],{"class":55,"line":77},[53,818,378],{"class":226},[53,820,381],{"class":226},[53,822,384],{"class":59},[53,824,825,827,829],{"class":55,"line":88},[53,826,389],{"class":226},[53,828,392],{"class":189},[53,830,395],{"class":59},[53,832,833],{"class":55,"line":99},[53,834,836],{"class":835},"sCsY4","    \u002F\u002F ...\n",[53,838,839],{"class":55,"line":270},[53,840,274],{"emptyLinePlaceholder":273},[53,842,843,845,848,850,853,856],{"class":55,"line":277},[53,844,599],{"class":226},[53,846,847],{"class":555}," octokit",[53,849,605],{"class":226},[53,851,852],{"class":226}," new",[53,854,855],{"class":189}," Octokit",[53,857,858],{"class":59},"()\n",[53,860,861],{"class":55,"line":301},[53,862,408],{"class":59},[53,864,865],{"class":55,"line":311},[53,866,413],{"class":59},[10,868,869],{},"Fetch the data by iterating over each project in every category:",[44,871,873],{"className":369,"code":872,"filename":796,"language":371,"meta":49,"style":49},"export default {\n  async load() {\n    \u002F\u002F ...\n\n    const loadedProjects = await Promise.all(\n      projects.map(async (project) => {\n        const projects = await Promise.all(\n          project.projects.map(async (project) => {\n            const [owner, repo] = project.split('\u002F')\n\n            const { data } = await octokit.rest.repos.get({\n              owner,\n              repo,\n            })\n\n            return {\n              name: project,\n              description: data.description,\n              url: data.html_url,\n            }\n          }),\n        )\n\n        return { ...project, projects }\n      }),\n    )\n\n    return loadedProjects\n  }\n}\n",[35,874,875,883,891,895,899,923,952,971,992,1028,1032,1058,1063,1068,1073,1077,1084,1089,1094,1099,1104,1109,1114,1118,1131,1136,1141,1145,1152,1156],{"__ignoreMap":49},[53,876,877,879,881],{"class":55,"line":56},[53,878,378],{"class":226},[53,880,381],{"class":226},[53,882,384],{"class":59},[53,884,885,887,889],{"class":55,"line":63},[53,886,389],{"class":226},[53,888,392],{"class":189},[53,890,395],{"class":59},[53,892,893],{"class":55,"line":77},[53,894,836],{"class":835},[53,896,897],{"class":55,"line":88},[53,898,274],{"emptyLinePlaceholder":273},[53,900,901,903,906,908,911,914,917,920],{"class":55,"line":99},[53,902,599],{"class":226},[53,904,905],{"class":555}," loadedProjects",[53,907,605],{"class":226},[53,909,910],{"class":226}," await",[53,912,913],{"class":555}," Promise",[53,915,916],{"class":59},".",[53,918,919],{"class":189},"all",[53,921,922],{"class":59},"(\n",[53,924,925,928,931,934,937,940,944,947,950],{"class":55,"line":270},[53,926,927],{"class":59},"      projects.",[53,929,930],{"class":189},"map",[53,932,933],{"class":59},"(",[53,935,936],{"class":226},"async",[53,938,939],{"class":59}," (",[53,941,943],{"class":942},"sP4rz","project",[53,945,946],{"class":59},") ",[53,948,949],{"class":226},"=>",[53,951,384],{"class":59},[53,953,954,957,959,961,963,965,967,969],{"class":55,"line":277},[53,955,956],{"class":226},"        const",[53,958,602],{"class":555},[53,960,605],{"class":226},[53,962,910],{"class":226},[53,964,913],{"class":555},[53,966,916],{"class":59},[53,968,919],{"class":189},[53,970,922],{"class":59},[53,972,973,976,978,980,982,984,986,988,990],{"class":55,"line":301},[53,974,975],{"class":59},"          project.projects.",[53,977,930],{"class":189},[53,979,933],{"class":59},[53,981,936],{"class":226},[53,983,939],{"class":59},[53,985,943],{"class":942},[53,987,946],{"class":59},[53,989,949],{"class":226},[53,991,384],{"class":59},[53,993,994,997,1000,1003,1006,1009,1012,1014,1017,1020,1022,1025],{"class":55,"line":311},[53,995,996],{"class":226},"            const",[53,998,999],{"class":59}," [",[53,1001,1002],{"class":555},"owner",[53,1004,1005],{"class":59},", ",[53,1007,1008],{"class":555},"repo",[53,1010,1011],{"class":59},"] ",[53,1013,193],{"class":226},[53,1015,1016],{"class":59}," project.",[53,1018,1019],{"class":189},"split",[53,1021,933],{"class":59},[53,1023,1024],{"class":73},"'\u002F'",[53,1026,1027],{"class":59},")\n",[53,1029,1030],{"class":55,"line":321},[53,1031,274],{"emptyLinePlaceholder":273},[53,1033,1034,1036,1039,1042,1045,1047,1049,1052,1055],{"class":55,"line":661},[53,1035,996],{"class":226},[53,1037,1038],{"class":59}," { ",[53,1040,1041],{"class":555},"data",[53,1043,1044],{"class":59}," } ",[53,1046,193],{"class":226},[53,1048,910],{"class":226},[53,1050,1051],{"class":59}," octokit.rest.repos.",[53,1053,1054],{"class":189},"get",[53,1056,1057],{"class":59},"({\n",[53,1059,1060],{"class":55,"line":669},[53,1061,1062],{"class":59},"              owner,\n",[53,1064,1065],{"class":55,"line":677},[53,1066,1067],{"class":59},"              repo,\n",[53,1069,1070],{"class":55,"line":683},[53,1071,1072],{"class":59},"            })\n",[53,1074,1075],{"class":55,"line":688},[53,1076,274],{"emptyLinePlaceholder":273},[53,1078,1079,1082],{"class":55,"line":693},[53,1080,1081],{"class":226},"            return",[53,1083,384],{"class":59},[53,1085,1086],{"class":55,"line":703},[53,1087,1088],{"class":59},"              name: project,\n",[53,1090,1091],{"class":55,"line":708},[53,1092,1093],{"class":59},"              description: data.description,\n",[53,1095,1096],{"class":55,"line":716},[53,1097,1098],{"class":59},"              url: data.html_url,\n",[53,1100,1101],{"class":55,"line":724},[53,1102,1103],{"class":59},"            }\n",[53,1105,1106],{"class":55,"line":732},[53,1107,1108],{"class":59},"          }),\n",[53,1110,1111],{"class":55,"line":737},[53,1112,1113],{"class":59},"        )\n",[53,1115,1116],{"class":55,"line":742},[53,1117,274],{"emptyLinePlaceholder":273},[53,1119,1120,1123,1125,1128],{"class":55,"line":747},[53,1121,1122],{"class":226},"        return",[53,1124,1038],{"class":59},[53,1126,1127],{"class":226},"...",[53,1129,1130],{"class":59},"project, projects }\n",[53,1132,1133],{"class":55,"line":757},[53,1134,1135],{"class":59},"      }),\n",[53,1137,1138],{"class":55,"line":767},[53,1139,1140],{"class":59},"    )\n",[53,1142,1143],{"class":55,"line":772},[53,1144,274],{"emptyLinePlaceholder":273},[53,1146,1147,1149],{"class":55,"line":778},[53,1148,400],{"class":226},[53,1150,1151],{"class":59}," loadedProjects\n",[53,1153,1154],{"class":55,"line":783},[53,1155,408],{"class":59},[53,1157,1159],{"class":55,"line":1158},30,[53,1160,413],{"class":59},[10,1162,1163],{},"To provide autocompletion in the Vue component loading this file, we can export the data type:",[44,1165,1167],{"className":369,"code":1166,"filename":796,"language":371,"meta":49,"style":49},"\u002F\u002F ...\n\ndeclare const data: {\n  title: string\n  projects: {\n    name: string\n    description: string\n    url: string\n  }[]\n}[]\nexport { data }\n\n\u002F\u002F ...\n",[35,1168,1169,1174,1178,1193,1203,1212,1221,1230,1239,1244,1249,1256,1260],{"__ignoreMap":49},[53,1170,1171],{"class":55,"line":56},[53,1172,1173],{"class":835},"\u002F\u002F ...\n",[53,1175,1176],{"class":55,"line":63},[53,1177,274],{"emptyLinePlaceholder":273},[53,1179,1180,1183,1186,1189,1191],{"class":55,"line":77},[53,1181,1182],{"class":226},"declare",[53,1184,1185],{"class":226}," const",[53,1187,1188],{"class":555}," data",[53,1190,366],{"class":226},[53,1192,384],{"class":59},[53,1194,1195,1198,1200],{"class":55,"line":88},[53,1196,1197],{"class":942},"  title",[53,1199,366],{"class":226},[53,1201,1202],{"class":555}," string\n",[53,1204,1205,1208,1210],{"class":55,"line":99},[53,1206,1207],{"class":942},"  projects",[53,1209,366],{"class":226},[53,1211,384],{"class":59},[53,1213,1214,1217,1219],{"class":55,"line":270},[53,1215,1216],{"class":942},"    name",[53,1218,366],{"class":226},[53,1220,1202],{"class":555},[53,1222,1223,1226,1228],{"class":55,"line":277},[53,1224,1225],{"class":942},"    description",[53,1227,366],{"class":226},[53,1229,1202],{"class":555},[53,1231,1232,1235,1237],{"class":55,"line":301},[53,1233,1234],{"class":942},"    url",[53,1236,366],{"class":226},[53,1238,1202],{"class":555},[53,1240,1241],{"class":55,"line":311},[53,1242,1243],{"class":59},"  }[]\n",[53,1245,1246],{"class":55,"line":321},[53,1247,1248],{"class":59},"}[]\n",[53,1250,1251,1253],{"class":55,"line":661},[53,1252,378],{"class":226},[53,1254,1255],{"class":59}," { data }\n",[53,1257,1258],{"class":55,"line":669},[53,1259,274],{"emptyLinePlaceholder":273},[53,1261,1262],{"class":55,"line":677},[53,1263,1173],{"class":835},[1265,1266,1268],"h3",{"id":1267},"exceed-the-rate-limit","Exceed the rate limit",[10,1270,1271,1272,1274,1275,1280,1281,1284,1285,916],{},"Without authentication, the ",[14,1273,24],{}," has a rate limit of ",[332,1276,1279],{"href":1277,"rel":1278},"https:\u002F\u002Fdocs.github.com\u002Fen\u002Frest\u002Fusing-the-rest-api\u002Frate-limits-for-the-rest-api?apiVersion=2022-11-28#primary-rate-limit-for-unauthenticated-users",[336],"60 requests per hour",". Even though data is fetched only at server startup, not on every page load, it's easy to hit this limit during development. To prevent this and increase the limit to 5,000 requests per hour, we can assign a ",[14,1282,1283],{},"personal access token"," to the ",[14,1286,1287],{},"Octokit instance",[1289,1290,1291],"ol",{},[1292,1293,1294,1295,1298,1299,1301],"li",{},"Create a ",[35,1296,1297],{},".env"," file in the VitePress source directory, which is the Vite root directory, thus in the ",[35,1300,41],{}," directory.",[567,1303,1306],{"color":1304,"icon":1305},"warning","i-ph-warning-duotone",[10,1307,1308,1309,1312],{},"Do not commit this file. Add it to your ",[35,1310,1311],{},".gitignore"," file.",[1289,1314,1315],{"start":63},[1292,1316,1317],{},"Insert your personal access token into this file:",[44,1319,1324],{"className":1320,"code":1322,"filename":796,"language":1323,"meta":49},[1321],"language-text","VITE_GITHUB_TOKEN=your-personal-access-token\n","text",[35,1325,1322],{"__ignoreMap":49},[10,1327,1328,1329,1334,1335,1338,1339,916],{},"Create a personal access token by following the ",[332,1330,1333],{"href":1331,"rel":1332},"https:\u002F\u002Fdocs.github.com\u002Fen\u002Fauthentication\u002Fkeeping-your-account-and-data-secure\u002Fmanaging-your-personal-access-tokens",[336],"GitHub documentation"," or using the ",[14,1336,1337],{},"GitHub CLI"," ",[35,1340,1341],{},"gh auth token",[1289,1343,1344],{"start":77},[1292,1345,1346,1347,1349],{},"Load this token in the ",[35,1348,532],{}," file:",[44,1351,1353],{"className":369,"code":1352,"filename":532,"language":371,"meta":49,"style":49},"import { join } from 'node:path'\nimport { Octokit } from 'octokit'\nimport { loadEnv } from 'vitepress'\n\nexport default {\n  async load() {\n    \u002F\u002F ...\n\n    const env = loadEnv('', join(process.cwd(), 'src'))\n    const octokit = new Octokit({ auth: env.VITE_GITHUB_TOKEN })\n\n    \u002F\u002F ...\n  }\n}\n",[35,1354,1355,1367,1377,1389,1393,1401,1409,1413,1417,1454,1475,1479,1483,1487],{"__ignoreMap":49},[53,1356,1357,1359,1362,1364],{"class":55,"line":56},[53,1358,474],{"class":226},[53,1360,1361],{"class":59}," { join } ",[53,1363,480],{"class":226},[53,1365,1366],{"class":73}," 'node:path'\n",[53,1368,1369,1371,1373,1375],{"class":55,"line":63},[53,1370,474],{"class":226},[53,1372,805],{"class":59},[53,1374,480],{"class":226},[53,1376,810],{"class":73},[53,1378,1379,1381,1384,1386],{"class":55,"line":77},[53,1380,474],{"class":226},[53,1382,1383],{"class":59}," { loadEnv } ",[53,1385,480],{"class":226},[53,1387,1388],{"class":73}," 'vitepress'\n",[53,1390,1391],{"class":55,"line":88},[53,1392,274],{"emptyLinePlaceholder":273},[53,1394,1395,1397,1399],{"class":55,"line":99},[53,1396,378],{"class":226},[53,1398,381],{"class":226},[53,1400,384],{"class":59},[53,1402,1403,1405,1407],{"class":55,"line":270},[53,1404,389],{"class":226},[53,1406,392],{"class":189},[53,1408,395],{"class":59},[53,1410,1411],{"class":55,"line":277},[53,1412,836],{"class":835},[53,1414,1415],{"class":55,"line":301},[53,1416,274],{"emptyLinePlaceholder":273},[53,1418,1419,1421,1424,1426,1429,1431,1434,1436,1439,1442,1445,1448,1451],{"class":55,"line":311},[53,1420,599],{"class":226},[53,1422,1423],{"class":555}," env",[53,1425,605],{"class":226},[53,1427,1428],{"class":189}," loadEnv",[53,1430,933],{"class":59},[53,1432,1433],{"class":73},"''",[53,1435,1005],{"class":59},[53,1437,1438],{"class":189},"join",[53,1440,1441],{"class":59},"(process.",[53,1443,1444],{"class":189},"cwd",[53,1446,1447],{"class":59},"(), ",[53,1449,1450],{"class":73},"'src'",[53,1452,1453],{"class":59},"))\n",[53,1455,1456,1458,1460,1462,1464,1466,1469,1472],{"class":55,"line":321},[53,1457,599],{"class":226},[53,1459,847],{"class":555},[53,1461,605],{"class":226},[53,1463,852],{"class":226},[53,1465,855],{"class":189},[53,1467,1468],{"class":59},"({ auth: env.",[53,1470,1471],{"class":555},"VITE_GITHUB_TOKEN",[53,1473,1474],{"class":59}," })\n",[53,1476,1477],{"class":55,"line":661},[53,1478,274],{"emptyLinePlaceholder":273},[53,1480,1481],{"class":55,"line":669},[53,1482,836],{"class":835},[53,1484,1485],{"class":55,"line":677},[53,1486,408],{"class":59},[53,1488,1489],{"class":55,"line":683},[53,1490,413],{"class":59},[10,1492,1493],{},"No more concerns about rate limit issues!",[27,1495,1497],{"id":1496},"displaying-the-projects","Displaying the projects",[10,1499,1500],{},"Having set up the page and gathered the data, it's time to display them.",[10,1502,1503,1504,38,1507,1510,1511,119],{},"First, create a component named ",[35,1505,1506],{},"ProjectCard.vue",[35,1508,1509],{},".vitepress\u002Ftheme\u002Fcomponents"," directory. It will be similar to the ",[35,1512,1513],{},"BlogCard.vue",[44,1515,1517],{"className":122,"code":1516,"filename":1513,"language":124,"meta":49,"style":49},"\u003Cscript lang=\"ts\" setup>\nimport type { Project } from '..\u002Ftypes\u002Fproject'\n\ndefineProps\u003C{\n  project: Project\n}>()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Carticle\n    class=\"group relative border-4 border-black bg-white p-6 shadow-[8px_8px_0_black] transition duration-150 ease-linear space-y-4 hover:shadow-[12px_12px_0_black] hover:-translate-x-1 hover:-translate-y-1\"\n  >\n    \u003Ch2 class=\"text-2xl text-black font-medium\">\n      \u003Ca :href=\"project.url\">\n        {{ project.name }}\n        \u003Cspan class=\"absolute inset-0\" \u002F>\n      \u003C\u002Fa>\n    \u003C\u002Fh2>\n\n    \u003Cp v-if=\"project.description\" class=\"text-lg text-black\">\n      {{ project.description }}\n    \u003C\u002Fp>\n  \u003C\u002Farticle>\n\u003C\u002Ftemplate>\n",[35,1518,1519,1535,1550,1554,1562,1572,1577,1585,1589,1597,1604,1614,1619,1634,1650,1655,1675,1684,1692,1696,1718,1723,1731,1740],{"__ignoreMap":49},[53,1520,1521,1523,1525,1527,1529,1531,1533],{"class":55,"line":56},[53,1522,131],{"class":59},[53,1524,456],{"class":66},[53,1526,459],{"class":189},[53,1528,193],{"class":59},[53,1530,464],{"class":73},[53,1532,467],{"class":189},[53,1534,137],{"class":59},[53,1536,1537,1539,1542,1545,1547],{"class":55,"line":63},[53,1538,474],{"class":226},[53,1540,1541],{"class":226}," type",[53,1543,1544],{"class":59}," { Project } ",[53,1546,480],{"class":226},[53,1548,1549],{"class":73}," '..\u002Ftypes\u002Fproject'\n",[53,1551,1552],{"class":55,"line":77},[53,1553,274],{"emptyLinePlaceholder":273},[53,1555,1556,1559],{"class":55,"line":88},[53,1557,1558],{"class":189},"defineProps",[53,1560,1561],{"class":59},"\u003C{\n",[53,1563,1564,1567,1569],{"class":55,"line":99},[53,1565,1566],{"class":942},"  project",[53,1568,366],{"class":226},[53,1570,1571],{"class":189}," Project\n",[53,1573,1574],{"class":55,"line":270},[53,1575,1576],{"class":59},"}>()\n",[53,1578,1579,1581,1583],{"class":55,"line":277},[53,1580,147],{"class":59},[53,1582,456],{"class":66},[53,1584,137],{"class":59},[53,1586,1587],{"class":55,"line":301},[53,1588,274],{"emptyLinePlaceholder":273},[53,1590,1591,1593,1595],{"class":55,"line":311},[53,1592,131],{"class":59},[53,1594,134],{"class":66},[53,1596,137],{"class":59},[53,1598,1599,1601],{"class":55,"line":321},[53,1600,183],{"class":59},[53,1602,1603],{"class":66},"article\n",[53,1605,1606,1609,1611],{"class":55,"line":661},[53,1607,1608],{"class":189},"    class",[53,1610,193],{"class":59},[53,1612,1613],{"class":73},"\"group relative border-4 border-black bg-white p-6 shadow-[8px_8px_0_black] transition duration-150 ease-linear space-y-4 hover:shadow-[12px_12px_0_black] hover:-translate-x-1 hover:-translate-y-1\"\n",[53,1615,1616],{"class":55,"line":669},[53,1617,1618],{"class":59},"  >\n",[53,1620,1621,1623,1625,1627,1629,1632],{"class":55,"line":677},[53,1622,203],{"class":59},[53,1624,27],{"class":66},[53,1626,190],{"class":189},[53,1628,193],{"class":59},[53,1630,1631],{"class":73},"\"text-2xl text-black font-medium\"",[53,1633,137],{"class":59},[53,1635,1636,1638,1640,1643,1645,1648],{"class":55,"line":683},[53,1637,220],{"class":59},[53,1639,332],{"class":66},[53,1641,1642],{"class":189}," :href",[53,1644,193],{"class":59},[53,1646,1647],{"class":73},"\"project.url\"",[53,1649,137],{"class":59},[53,1651,1652],{"class":55,"line":688},[53,1653,1654],{"class":59},"        {{ project.name }}\n",[53,1656,1657,1660,1662,1664,1666,1669,1673],{"class":55,"line":693},[53,1658,1659],{"class":59},"        \u003C",[53,1661,53],{"class":66},[53,1663,190],{"class":189},[53,1665,193],{"class":59},[53,1667,1668],{"class":73},"\"absolute inset-0\"",[53,1670,1672],{"class":1671},"sPrNH"," \u002F",[53,1674,137],{"class":59},[53,1676,1677,1680,1682],{"class":55,"line":703},[53,1678,1679],{"class":59},"      \u003C\u002F",[53,1681,332],{"class":66},[53,1683,137],{"class":59},[53,1685,1686,1688,1690],{"class":55,"line":708},[53,1687,304],{"class":59},[53,1689,27],{"class":66},[53,1691,137],{"class":59},[53,1693,1694],{"class":55,"line":716},[53,1695,274],{"emptyLinePlaceholder":273},[53,1697,1698,1700,1702,1704,1706,1709,1711,1713,1716],{"class":55,"line":724},[53,1699,203],{"class":59},[53,1701,10],{"class":66},[53,1703,227],{"class":189},[53,1705,193],{"class":59},[53,1707,1708],{"class":73},"\"project.description\"",[53,1710,190],{"class":189},[53,1712,193],{"class":59},[53,1714,1715],{"class":73},"\"text-lg text-black\"",[53,1717,137],{"class":59},[53,1719,1720],{"class":55,"line":732},[53,1721,1722],{"class":59},"      {{ project.description }}\n",[53,1724,1725,1727,1729],{"class":55,"line":737},[53,1726,304],{"class":59},[53,1728,10],{"class":66},[53,1730,137],{"class":59},[53,1732,1733,1735,1738],{"class":55,"line":742},[53,1734,314],{"class":59},[53,1736,1737],{"class":66},"article",[53,1739,137],{"class":59},[53,1741,1742,1744,1746],{"class":55,"line":747},[53,1743,147],{"class":59},[53,1745,134],{"class":66},[53,1747,137],{"class":59},[10,1749,1750,1751,1754,1755,1349],{},"As observed, we are utilizing a ",[35,1752,1753],{},"Project"," type, which we need to establish in the ",[35,1756,1757],{},"types\u002Fproject.ts",[44,1759,1761],{"className":369,"code":1760,"filename":1757,"language":371,"meta":49,"style":49},"export interface Project {\n  name: string\n  description: string | null\n  url: string\n}\n",[35,1762,1763,1775,1784,1800,1809],{"__ignoreMap":49},[53,1764,1765,1767,1770,1773],{"class":55,"line":56},[53,1766,378],{"class":226},[53,1768,1769],{"class":226}," interface",[53,1771,1772],{"class":189}," Project",[53,1774,384],{"class":59},[53,1776,1777,1780,1782],{"class":55,"line":63},[53,1778,1779],{"class":942},"  name",[53,1781,366],{"class":226},[53,1783,1202],{"class":555},[53,1785,1786,1789,1791,1794,1797],{"class":55,"line":77},[53,1787,1788],{"class":942},"  description",[53,1790,366],{"class":226},[53,1792,1793],{"class":555}," string",[53,1795,1796],{"class":226}," |",[53,1798,1799],{"class":555}," null\n",[53,1801,1802,1805,1807],{"class":55,"line":88},[53,1803,1804],{"class":942},"  url",[53,1806,366],{"class":226},[53,1808,1202],{"class":555},[53,1810,1811],{"class":55,"line":99},[53,1812,413],{"class":59},[10,1814,1815,1816,1818,1819,1821],{},"The great aspect is that we can apply this type in the ",[35,1817,532],{}," file to ensure the data retrieved from the ",[14,1820,24],{}," aligns with the expected format for display. This is an effective strategy to prevent errors if we modify the data structure in one location but forget to update elsewhere.",[10,1823,1824,1825,1827],{},"In the ",[35,1826,532],{}," file, we can now import this type and utilize it:",[44,1829,1832],{"className":1830,"code":1831,"filename":532,"language":371,"meta":49,"style":49},"language-ts shiki shiki-themes github-light github-light github-dark has-highlighted","\u002F\u002F ...\nimport { Project } from '..\u002Ftheme\u002Ftypes\u002Fproject'\n\ndeclare const data: {\n  title: string\n  projects: Project[] \u002F\u002F [!code highlight]\n}[]\nexport { data }\n\nexport default {\n  async load() {\n    \u002F\u002F ...\n\n    const loadedProjects = await Promise.all(\n      projects.map(async (project) => {\n        const projects = await Promise.all(\n          project.projects.map(async (project) => {\n            const [owner, repo] = project.split('\u002F')\n\n            const { data } = await octokit.rest.repos.get({\n              owner,\n              repo,\n            })\n\n            return {\n              name: project,\n              description: data.description,\n              url: data.html_url,\n            } satisfies Project \u002F\u002F [!code highlight]\n          }),\n        )\n\n        return { ...project, projects }\n      }),\n    )\n\n    return loadedProjects\n  }\n}\n",[35,1833,1834,1838,1849,1853,1865,1873,1886,1890,1896,1900,1908,1916,1920,1924,1942,1962,1980,2000,2026,2030,2050,2054,2058,2062,2066,2072,2076,2080,2084,2095,2099,2104,2109,2120,2125,2130,2135,2142,2147],{"__ignoreMap":49},[53,1835,1836],{"class":55,"line":56},[53,1837,1173],{"class":835},[53,1839,1840,1842,1844,1846],{"class":55,"line":63},[53,1841,474],{"class":226},[53,1843,1544],{"class":59},[53,1845,480],{"class":226},[53,1847,1848],{"class":73}," '..\u002Ftheme\u002Ftypes\u002Fproject'\n",[53,1850,1851],{"class":55,"line":77},[53,1852,274],{"emptyLinePlaceholder":273},[53,1854,1855,1857,1859,1861,1863],{"class":55,"line":88},[53,1856,1182],{"class":226},[53,1858,1185],{"class":226},[53,1860,1188],{"class":555},[53,1862,366],{"class":226},[53,1864,384],{"class":59},[53,1866,1867,1869,1871],{"class":55,"line":99},[53,1868,1197],{"class":942},[53,1870,366],{"class":226},[53,1872,1202],{"class":555},[53,1874,1877,1879,1881,1883],{"class":1875,"line":270},[55,1876],"highlighted",[53,1878,1207],{"class":942},[53,1880,366],{"class":226},[53,1882,1772],{"class":189},[53,1884,1885],{"class":59},"[] ",[53,1887,1888],{"class":55,"line":277},[53,1889,1248],{"class":59},[53,1891,1892,1894],{"class":55,"line":301},[53,1893,378],{"class":226},[53,1895,1255],{"class":59},[53,1897,1898],{"class":55,"line":311},[53,1899,274],{"emptyLinePlaceholder":273},[53,1901,1902,1904,1906],{"class":55,"line":321},[53,1903,378],{"class":226},[53,1905,381],{"class":226},[53,1907,384],{"class":59},[53,1909,1910,1912,1914],{"class":55,"line":661},[53,1911,389],{"class":226},[53,1913,392],{"class":189},[53,1915,395],{"class":59},[53,1917,1918],{"class":55,"line":669},[53,1919,836],{"class":835},[53,1921,1922],{"class":55,"line":677},[53,1923,274],{"emptyLinePlaceholder":273},[53,1925,1926,1928,1930,1932,1934,1936,1938,1940],{"class":55,"line":683},[53,1927,599],{"class":226},[53,1929,905],{"class":555},[53,1931,605],{"class":226},[53,1933,910],{"class":226},[53,1935,913],{"class":555},[53,1937,916],{"class":59},[53,1939,919],{"class":189},[53,1941,922],{"class":59},[53,1943,1944,1946,1948,1950,1952,1954,1956,1958,1960],{"class":55,"line":688},[53,1945,927],{"class":59},[53,1947,930],{"class":189},[53,1949,933],{"class":59},[53,1951,936],{"class":226},[53,1953,939],{"class":59},[53,1955,943],{"class":942},[53,1957,946],{"class":59},[53,1959,949],{"class":226},[53,1961,384],{"class":59},[53,1963,1964,1966,1968,1970,1972,1974,1976,1978],{"class":55,"line":693},[53,1965,956],{"class":226},[53,1967,602],{"class":555},[53,1969,605],{"class":226},[53,1971,910],{"class":226},[53,1973,913],{"class":555},[53,1975,916],{"class":59},[53,1977,919],{"class":189},[53,1979,922],{"class":59},[53,1981,1982,1984,1986,1988,1990,1992,1994,1996,1998],{"class":55,"line":703},[53,1983,975],{"class":59},[53,1985,930],{"class":189},[53,1987,933],{"class":59},[53,1989,936],{"class":226},[53,1991,939],{"class":59},[53,1993,943],{"class":942},[53,1995,946],{"class":59},[53,1997,949],{"class":226},[53,1999,384],{"class":59},[53,2001,2002,2004,2006,2008,2010,2012,2014,2016,2018,2020,2022,2024],{"class":55,"line":708},[53,2003,996],{"class":226},[53,2005,999],{"class":59},[53,2007,1002],{"class":555},[53,2009,1005],{"class":59},[53,2011,1008],{"class":555},[53,2013,1011],{"class":59},[53,2015,193],{"class":226},[53,2017,1016],{"class":59},[53,2019,1019],{"class":189},[53,2021,933],{"class":59},[53,2023,1024],{"class":73},[53,2025,1027],{"class":59},[53,2027,2028],{"class":55,"line":716},[53,2029,274],{"emptyLinePlaceholder":273},[53,2031,2032,2034,2036,2038,2040,2042,2044,2046,2048],{"class":55,"line":724},[53,2033,996],{"class":226},[53,2035,1038],{"class":59},[53,2037,1041],{"class":555},[53,2039,1044],{"class":59},[53,2041,193],{"class":226},[53,2043,910],{"class":226},[53,2045,1051],{"class":59},[53,2047,1054],{"class":189},[53,2049,1057],{"class":59},[53,2051,2052],{"class":55,"line":732},[53,2053,1062],{"class":59},[53,2055,2056],{"class":55,"line":737},[53,2057,1067],{"class":59},[53,2059,2060],{"class":55,"line":742},[53,2061,1072],{"class":59},[53,2063,2064],{"class":55,"line":747},[53,2065,274],{"emptyLinePlaceholder":273},[53,2067,2068,2070],{"class":55,"line":757},[53,2069,1081],{"class":226},[53,2071,384],{"class":59},[53,2073,2074],{"class":55,"line":767},[53,2075,1088],{"class":59},[53,2077,2078],{"class":55,"line":772},[53,2079,1093],{"class":59},[53,2081,2082],{"class":55,"line":778},[53,2083,1098],{"class":59},[53,2085,2087,2090,2093],{"class":2086,"line":783},[55,1876],[53,2088,2089],{"class":59},"            } ",[53,2091,2092],{"class":226},"satisfies",[53,2094,1772],{"class":189},[53,2096,2097],{"class":55,"line":1158},[53,2098,1108],{"class":59},[53,2100,2102],{"class":55,"line":2101},31,[53,2103,1113],{"class":59},[53,2105,2107],{"class":55,"line":2106},32,[53,2108,274],{"emptyLinePlaceholder":273},[53,2110,2112,2114,2116,2118],{"class":55,"line":2111},33,[53,2113,1122],{"class":226},[53,2115,1038],{"class":59},[53,2117,1127],{"class":226},[53,2119,1130],{"class":59},[53,2121,2123],{"class":55,"line":2122},34,[53,2124,1135],{"class":59},[53,2126,2128],{"class":55,"line":2127},35,[53,2129,1140],{"class":59},[53,2131,2133],{"class":55,"line":2132},36,[53,2134,274],{"emptyLinePlaceholder":273},[53,2136,2138,2140],{"class":55,"line":2137},37,[53,2139,400],{"class":226},[53,2141,1151],{"class":59},[53,2143,2145],{"class":55,"line":2144},38,[53,2146,408],{"class":59},[53,2148,2150],{"class":55,"line":2149},39,[53,2151,413],{"class":59},[10,2153,2154,2155,119],{},"Lastly, display the data in the ",[35,2156,111],{},[44,2158,2160],{"className":122,"code":2159,"filename":111,"language":124,"meta":49,"style":49},"\u003Cscript lang=\"ts\" setup>\nimport { data } from '..\u002F..\u002F..\u002Fdata\u002Fgithub-projects.data'\n\nconst { frontmatter } = useData()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Csection class=\"space-y-16\">\n    \u003Ch1 class=\"text-6xl font-semibold\">\n      {{ frontmatter.title }}\n    \u003C\u002Fh1>\n\n    \u003Cdiv v-for=\"section in data\" :key=\"section.title\" class=\"space-y-20\">\n      \u003Csection class=\"space-y-10\">\n        \u003Ch2 class=\"text-4xl font-semibold\">\n          {{ section.title }}\n        \u003C\u002Fh2>\n\n        \u003CProjectCard\n          v-for=\"project in section.projects\"\n          :key=\"project.url\"\n          :project=\"project\"\n        \u002F>\n      \u003C\u002Fsection>\n    \u003C\u002Fdiv>\n\n    \u003Cdiv class=\"flex justify-center\">\n      \u003CButtonPrimary href=\"\u002F\">\n        Back to Home\n      \u003C\u002FButtonPrimary>\n    \u003C\u002Fdiv>\n  \u003C\u002Fsection>\n\u003C\u002Ftemplate>\n",[35,2161,2162,2178,2188,2192,2211,2219,2223,2231,2247,2263,2268,2276,2280,2311,2326,2341,2346,2355,2359,2366,2387,2404,2418,2423,2431,2439,2443,2458,2475,2480,2488,2496,2504],{"__ignoreMap":49},[53,2163,2164,2166,2168,2170,2172,2174,2176],{"class":55,"line":56},[53,2165,131],{"class":59},[53,2167,456],{"class":66},[53,2169,459],{"class":189},[53,2171,193],{"class":59},[53,2173,464],{"class":73},[53,2175,467],{"class":189},[53,2177,137],{"class":59},[53,2179,2180,2182,2184,2186],{"class":55,"line":63},[53,2181,474],{"class":226},[53,2183,477],{"class":59},[53,2185,480],{"class":226},[53,2187,483],{"class":73},[53,2189,2190],{"class":55,"line":77},[53,2191,274],{"emptyLinePlaceholder":273},[53,2193,2194,2197,2199,2202,2204,2206,2209],{"class":55,"line":88},[53,2195,2196],{"class":226},"const",[53,2198,1038],{"class":59},[53,2200,2201],{"class":555},"frontmatter",[53,2203,1044],{"class":59},[53,2205,193],{"class":226},[53,2207,2208],{"class":189}," useData",[53,2210,858],{"class":59},[53,2212,2213,2215,2217],{"class":55,"line":99},[53,2214,147],{"class":59},[53,2216,456],{"class":66},[53,2218,137],{"class":59},[53,2220,2221],{"class":55,"line":270},[53,2222,274],{"emptyLinePlaceholder":273},[53,2224,2225,2227,2229],{"class":55,"line":277},[53,2226,131],{"class":59},[53,2228,134],{"class":66},[53,2230,137],{"class":59},[53,2232,2233,2235,2238,2240,2242,2245],{"class":55,"line":301},[53,2234,183],{"class":59},[53,2236,2237],{"class":66},"section",[53,2239,190],{"class":189},[53,2241,193],{"class":59},[53,2243,2244],{"class":73},"\"space-y-16\"",[53,2246,137],{"class":59},[53,2248,2249,2251,2254,2256,2258,2261],{"class":55,"line":311},[53,2250,203],{"class":59},[53,2252,2253],{"class":66},"h1",[53,2255,190],{"class":189},[53,2257,193],{"class":59},[53,2259,2260],{"class":73},"\"text-6xl font-semibold\"",[53,2262,137],{"class":59},[53,2264,2265],{"class":55,"line":321},[53,2266,2267],{"class":59},"      {{ frontmatter.title }}\n",[53,2269,2270,2272,2274],{"class":55,"line":661},[53,2271,304],{"class":59},[53,2273,2253],{"class":66},[53,2275,137],{"class":59},[53,2277,2278],{"class":55,"line":669},[53,2279,274],{"emptyLinePlaceholder":273},[53,2281,2282,2284,2286,2289,2291,2294,2297,2299,2302,2304,2306,2309],{"class":55,"line":677},[53,2283,203],{"class":59},[53,2285,186],{"class":66},[53,2287,2288],{"class":189}," v-for",[53,2290,193],{"class":59},[53,2292,2293],{"class":73},"\"section in data\"",[53,2295,2296],{"class":189}," :key",[53,2298,193],{"class":59},[53,2300,2301],{"class":73},"\"section.title\"",[53,2303,190],{"class":189},[53,2305,193],{"class":59},[53,2307,2308],{"class":73},"\"space-y-20\"",[53,2310,137],{"class":59},[53,2312,2313,2315,2317,2319,2321,2324],{"class":55,"line":683},[53,2314,220],{"class":59},[53,2316,2237],{"class":66},[53,2318,190],{"class":189},[53,2320,193],{"class":59},[53,2322,2323],{"class":73},"\"space-y-10\"",[53,2325,137],{"class":59},[53,2327,2328,2330,2332,2334,2336,2339],{"class":55,"line":688},[53,2329,1659],{"class":59},[53,2331,27],{"class":66},[53,2333,190],{"class":189},[53,2335,193],{"class":59},[53,2337,2338],{"class":73},"\"text-4xl font-semibold\"",[53,2340,137],{"class":59},[53,2342,2343],{"class":55,"line":693},[53,2344,2345],{"class":59},"          {{ section.title }}\n",[53,2347,2348,2351,2353],{"class":55,"line":703},[53,2349,2350],{"class":59},"        \u003C\u002F",[53,2352,27],{"class":66},[53,2354,137],{"class":59},[53,2356,2357],{"class":55,"line":708},[53,2358,274],{"emptyLinePlaceholder":273},[53,2360,2361,2363],{"class":55,"line":716},[53,2362,1659],{"class":59},[53,2364,2365],{"class":66},"ProjectCard\n",[53,2367,2368,2371,2373,2375,2378,2381,2384],{"class":55,"line":724},[53,2369,2370],{"class":226},"          v-for",[53,2372,193],{"class":59},[53,2374,232],{"class":73},[53,2376,2377],{"class":59},"project ",[53,2379,2380],{"class":226},"in",[53,2382,2383],{"class":59}," section.projects",[53,2385,2386],{"class":73},"\"\n",[53,2388,2389,2392,2395,2397,2399,2402],{"class":55,"line":732},[53,2390,2391],{"class":59},"          :",[53,2393,2394],{"class":189},"key",[53,2396,193],{"class":59},[53,2398,232],{"class":73},[53,2400,2401],{"class":59},"project.url",[53,2403,2386],{"class":73},[53,2405,2406,2408,2410,2412,2414,2416],{"class":55,"line":737},[53,2407,2391],{"class":59},[53,2409,943],{"class":189},[53,2411,193],{"class":59},[53,2413,232],{"class":73},[53,2415,943],{"class":59},[53,2417,2386],{"class":73},[53,2419,2420],{"class":55,"line":742},[53,2421,2422],{"class":59},"        \u002F>\n",[53,2424,2425,2427,2429],{"class":55,"line":747},[53,2426,1679],{"class":59},[53,2428,2237],{"class":66},[53,2430,137],{"class":59},[53,2432,2433,2435,2437],{"class":55,"line":757},[53,2434,304],{"class":59},[53,2436,186],{"class":66},[53,2438,137],{"class":59},[53,2440,2441],{"class":55,"line":767},[53,2442,274],{"emptyLinePlaceholder":273},[53,2444,2445,2447,2449,2451,2453,2456],{"class":55,"line":772},[53,2446,203],{"class":59},[53,2448,186],{"class":66},[53,2450,190],{"class":189},[53,2452,193],{"class":59},[53,2454,2455],{"class":73},"\"flex justify-center\"",[53,2457,137],{"class":59},[53,2459,2460,2462,2465,2468,2470,2473],{"class":55,"line":778},[53,2461,220],{"class":59},[53,2463,2464],{"class":66},"ButtonPrimary",[53,2466,2467],{"class":189}," href",[53,2469,193],{"class":59},[53,2471,2472],{"class":73},"\"\u002F\"",[53,2474,137],{"class":59},[53,2476,2477],{"class":55,"line":783},[53,2478,2479],{"class":59},"        Back to Home\n",[53,2481,2482,2484,2486],{"class":55,"line":1158},[53,2483,1679],{"class":59},[53,2485,2464],{"class":66},[53,2487,137],{"class":59},[53,2489,2490,2492,2494],{"class":55,"line":2101},[53,2491,304],{"class":59},[53,2493,186],{"class":66},[53,2495,137],{"class":59},[53,2497,2498,2500,2502],{"class":55,"line":2106},[53,2499,314],{"class":59},[53,2501,2237],{"class":66},[53,2503,137],{"class":59},[53,2505,2506,2508,2510],{"class":55,"line":2111},[53,2507,147],{"class":59},[53,2509,134],{"class":66},[53,2511,137],{"class":59},[10,2513,2514,2515,2518,2519,2521],{},"This component is straightforward. It iterates over each category of projects and displays them using the ",[35,2516,2517],{},"ProjectCard"," component. Additionally, a button leading back to the home page is included, consistent with other pages. The imported data is straightforward to consume due to its definition in the ",[35,2520,532],{}," file, minimizing the need for manipulation within the component. This methodology is preferable to maintain simplicity in the component and place logic at build time.",[339,2523,2524,2528],{},[342,2525],{"alt":2526,"src":2527},"Our new projects page with GitHub projects","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fshowcase-your-github-projects-on-your-vitepress-blog\u002Fvitepress-projects.png",[347,2529,2526],{},[10,2531,2532,2533,2535,2536,2539,2540,2543],{},"With this practical example, we now have a deeper understanding of the versatility and efficacy of ",[14,2534,16],{},". They even allow integration with a ",[14,2537,2538],{},"headless CMS"," to display your content or ",[14,2541,2542],{},"a database"," to access your data. The possibilities are truly limitless!",[2545,2546,2547],"style",{},"html pre.shiki code .sxrX7, html code.shiki .sxrX7{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sovSZ, html code.shiki .sovSZ{--shiki-light:#22863A;--shiki-default:#22863A;--shiki-dark:#85E89D}html pre.shiki code .sIIMD, html code.shiki .sIIMD{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}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 .snPdu, html code.shiki .snPdu{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .s8jYJ, html code.shiki .s8jYJ{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sP4rz, html code.shiki .sP4rz{--shiki-light:#E36209;--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sPrNH, html code.shiki .sPrNH{--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-default:#B31D28;--shiki-default-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic}",{"title":49,"searchDepth":63,"depth":63,"links":2549},[2550,2551,2554],{"id":29,"depth":63,"text":30},{"id":351,"depth":63,"text":352,"children":2552},[2553],{"id":1267,"depth":77,"text":1268},{"id":1496,"depth":63,"text":1497},"a4a933b8-07a5-4587-ad54-c3f9e30cbf45","2024-11-01","Enhance your VitePress blog with GitHub projects. Learn API data retrieval and how to display your projects on your blog.",{"branch":2559},"07.showcase-your-github-projects",null,{},"\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fshowcase-your-github-projects-on-your-vitepress-blog","---\ncontentId: a4a933b8-07a5-4587-ad54-c3f9e30cbf45\npart: 7\ntitle: Showcase Your GitHub Projects on Your VitePress Blog\ndescription: Enhance your VitePress blog with GitHub projects. Learn API data retrieval and how to display your projects on your blog.\ngithub:\n  branch: 07.showcase-your-github-projects\ndate: 2024-11-01\nseriesSlug: create-a-blog-with-vitepress-and-vue-js-from-scratch\n---\n\nIn today's tutorial, we will extend our exploration of **VitePress data loaders**, initiated in the episode on constructing a blog index page. This time, our focus will be on highlighting your **GitHub projects** by utilizing the **GitHub API**. Exciting, isn't it?\n\n## Crafting a new page\n\nAs ever, a new page begins with a fresh Markdown file. Create a file entitled `projects.md` in the `src` directory. This file, akin to the blog index page, will only contain frontmatter since the content will be dynamically loaded.\n\n```md [projects.md]\n---\nlayout: projects\ntitle: Projects\ndescription: Explore my projects.\n---\n```\n\nNext, we need to create the **Vue component** that will format our page. Insert a new file named `ProjectsIndex.vue` in the `.vitepress\u002Ftheme\u002Fpages\u002FProjects` directory. This component will resemble the `BlogIndex.vue` component:\n\n```vue [BlogIndex.vue]\n\u003Ctemplate>\n  projects\n\u003C\u002Ftemplate>\n```\n\nFinally, link the newly created page to the layout `projects` specified in the `projects.md` file. To accomplish this, open the `Layout.vue` file and incorporate this page:\n\n```vue [Layout.vue]\n\u003Ctemplate>\n  \u003Cdiv class=\"min-h-screen bg-[#FC88FF] py-16\">\n    \u003Cmain class=\"mx-auto max-w-screen-md\">\n      \u003CBlogIndex v-if=\"frontmatter.layout === 'blog'\" \u002F>\n      \u003CBlogShow v-else-if=\"frontmatter.layout === 'blog-show'\" \u002F>\n\n      \u003CProjectsIndex v-else-if=\"frontmatter.layout === 'projects'\" \u002F> \u002F\u002F [!code ++]\n    \u003C\u002Fmain>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n```\n\nNavigate to [http:\u002F\u002Flocalhost:3000\u002Fprojects](http:\u002F\u002Flocalhost:3000\u002Fprojects) to view the new page, which appears rather empty at the moment.\n\n![Our new empty projects page](\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fshowcase-your-github-projects-on-your-vitepress-blog\u002Fvitepress-projects-empty.png)\n\n## Retrieving GitHub projects\n\nNow, we need to retrieve data from **GitHub** to showcase on this page. We will use both the GitHub API for accessing up-to-date information and the VitePress data loaders to fetch data only during build time. Real-time data is unnecessary for this purpose.\n\nFirst, establish a loader in `.vitepress\u002Fdata\u002Fgithub-projects.data.ts`:\n\n```ts [.vitepress\u002Fdata\u002Fgithub-projects.data.ts]\nexport default {\n  async load() {\n    return 'hello projects'\n  }\n}\n```\n\nRemember that the `.data.ts` extension is essential to notify **VitePress** that this file functions as a data loader. VitePress uses a Vite plugin to [detect imports from a `.data.ts` file](https:\u002F\u002Fgithub.com\u002Fvuejs\u002Fvitepress\u002Fblob\u002Fmain\u002Fsrc\u002Fnode\u002Fplugins\u002FstaticDataPlugin.ts#L11). Upon detection, data loading occurs, returning only the results to the client. Consequently, data is transformed during build time, offering immediate browser availability, akin to [virtual modules in Vite](https:\u002F\u002Fvite.dev\u002Fguide\u002Fapi-plugin#virtual-modules-convention), yet more tailored to VitePress' needs.\n\nThen, load this file in the `ProjectsIndex.vue` component:\n\n```vue [ProjectsIndex.vue]\n\u003Cscript lang=\"ts\" setup>\nimport { data } from '..\u002F..\u002F..\u002Fdata\u002Fgithub-projects.data'\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  {{ data }}\n\u003C\u002Ftemplate>\n```\n\nOur page now displays the text `hello projects`. It's a promising beginning!\n\nWith this setup, we can now retrieve the **GitHub projects** data. Return to our `github-projects.data.ts` file and fetch data from the GitHub API. To facilitate this, we will install the `octokit` package:\n\n```bash [github-projects.data.ts]\npnpm add -D octokit\n```\n\nThen, edit the `github-projects.data.ts` file. To ease future modifications, let's create an array organizing all our projects into categories.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThis is an example, but remember that you can structure the data as you prefer.\n::\n\n```ts [github-projects.data.ts]\nexport default {\n  async load() {\n    const projects = [\n      {\n        title: 'Website',\n        projects: ['barbapapazes\u002Forion'],\n      },\n      {\n        title: 'Nuxt Modules',\n        projects: [\n          'barbapapazes\u002Fnuxt-authorization',\n          'barbapapazes\u002Fnuxt-payload-analyzer',\n        ],\n      },\n      {\n        title: 'Nuxt Templates',\n        projects: [\n          'barbapapazes\u002Fgavarnie',\n          'barbapapazes\u002Fslantire',\n          'barbapapazes\u002Fthe-green-chronicle',\n        ],\n      },\n      {\n        title: 'Tools',\n        projects: ['barbapapazes\u002Futils-ai'],\n      },\n    ]\n  }\n}\n```\n\nNext, create an **Octokit** instance for fetching data:\n\n```ts [Example]\nimport { Octokit } from 'octokit'\n\nexport default {\n  async load() {\n    \u002F\u002F ...\n\n    const octokit = new Octokit()\n  }\n}\n```\n\nFetch the data by iterating over each project in every category:\n\n```ts [Example]\nexport default {\n  async load() {\n    \u002F\u002F ...\n\n    const loadedProjects = await Promise.all(\n      projects.map(async (project) => {\n        const projects = await Promise.all(\n          project.projects.map(async (project) => {\n            const [owner, repo] = project.split('\u002F')\n\n            const { data } = await octokit.rest.repos.get({\n              owner,\n              repo,\n            })\n\n            return {\n              name: project,\n              description: data.description,\n              url: data.html_url,\n            }\n          }),\n        )\n\n        return { ...project, projects }\n      }),\n    )\n\n    return loadedProjects\n  }\n}\n```\n\nTo provide autocompletion in the Vue component loading this file, we can export the data type:\n\n```ts [Example]\n\u002F\u002F ...\n\ndeclare const data: {\n  title: string\n  projects: {\n    name: string\n    description: string\n    url: string\n  }[]\n}[]\nexport { data }\n\n\u002F\u002F ...\n```\n\n### Exceed the rate limit\n\nWithout authentication, the **GitHub API** has a rate limit of [60 requests per hour](https:\u002F\u002Fdocs.github.com\u002Fen\u002Frest\u002Fusing-the-rest-api\u002Frate-limits-for-the-rest-api?apiVersion=2022-11-28#primary-rate-limit-for-unauthenticated-users). Even though data is fetched only at server startup, not on every page load, it's easy to hit this limit during development. To prevent this and increase the limit to 5,000 requests per hour, we can assign a **personal access token** to the **Octokit instance**.\n\n1. Create a `.env` file in the VitePress source directory, which is the Vite root directory, thus in the `src` directory.\n\n::callout{icon=\"i-ph-warning-duotone\" color=\"warning\"}\nDo not commit this file. Add it to your `.gitignore` file.\n::\n\n2. Insert your personal access token into this file:\n\n```text [Example]\nVITE_GITHUB_TOKEN=your-personal-access-token\n```\n\nCreate a personal access token by following the [GitHub documentation](https:\u002F\u002Fdocs.github.com\u002Fen\u002Fauthentication\u002Fkeeping-your-account-and-data-secure\u002Fmanaging-your-personal-access-tokens) or using the **GitHub CLI** `gh auth token`.\n\n3. Load this token in the `github-projects.data.ts` file:\n\n```ts [github-projects.data.ts]\nimport { join } from 'node:path'\nimport { Octokit } from 'octokit'\nimport { loadEnv } from 'vitepress'\n\nexport default {\n  async load() {\n    \u002F\u002F ...\n\n    const env = loadEnv('', join(process.cwd(), 'src'))\n    const octokit = new Octokit({ auth: env.VITE_GITHUB_TOKEN })\n\n    \u002F\u002F ...\n  }\n}\n```\n\nNo more concerns about rate limit issues!\n\n## Displaying the projects\n\nHaving set up the page and gathered the data, it's time to display them.\n\nFirst, create a component named `ProjectCard.vue` in the `.vitepress\u002Ftheme\u002Fcomponents` directory. It will be similar to the `BlogCard.vue` component:\n\n```vue [BlogCard.vue]\n\u003Cscript lang=\"ts\" setup>\nimport type { Project } from '..\u002Ftypes\u002Fproject'\n\ndefineProps\u003C{\n  project: Project\n}>()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Carticle\n    class=\"group relative border-4 border-black bg-white p-6 shadow-[8px_8px_0_black] transition duration-150 ease-linear space-y-4 hover:shadow-[12px_12px_0_black] hover:-translate-x-1 hover:-translate-y-1\"\n  >\n    \u003Ch2 class=\"text-2xl text-black font-medium\">\n      \u003Ca :href=\"project.url\">\n        {{ project.name }}\n        \u003Cspan class=\"absolute inset-0\" \u002F>\n      \u003C\u002Fa>\n    \u003C\u002Fh2>\n\n    \u003Cp v-if=\"project.description\" class=\"text-lg text-black\">\n      {{ project.description }}\n    \u003C\u002Fp>\n  \u003C\u002Farticle>\n\u003C\u002Ftemplate>\n```\n\nAs observed, we are utilizing a `Project` type, which we need to establish in the `types\u002Fproject.ts` file:\n\n```ts [types\u002Fproject.ts]\nexport interface Project {\n  name: string\n  description: string | null\n  url: string\n}\n```\n\nThe great aspect is that we can apply this type in the `github-projects.data.ts` file to ensure the data retrieved from the **GitHub API** aligns with the expected format for display. This is an effective strategy to prevent errors if we modify the data structure in one location but forget to update elsewhere.\n\nIn the `github-projects.data.ts` file, we can now import this type and utilize it:\n\n```ts [github-projects.data.ts]\n\u002F\u002F ...\nimport { Project } from '..\u002Ftheme\u002Ftypes\u002Fproject'\n\ndeclare const data: {\n  title: string\n  projects: Project[] \u002F\u002F [!code highlight]\n}[]\nexport { data }\n\nexport default {\n  async load() {\n    \u002F\u002F ...\n\n    const loadedProjects = await Promise.all(\n      projects.map(async (project) => {\n        const projects = await Promise.all(\n          project.projects.map(async (project) => {\n            const [owner, repo] = project.split('\u002F')\n\n            const { data } = await octokit.rest.repos.get({\n              owner,\n              repo,\n            })\n\n            return {\n              name: project,\n              description: data.description,\n              url: data.html_url,\n            } satisfies Project \u002F\u002F [!code highlight]\n          }),\n        )\n\n        return { ...project, projects }\n      }),\n    )\n\n    return loadedProjects\n  }\n}\n```\n\nLastly, display the data in the `ProjectsIndex.vue` component:\n\n```vue [ProjectsIndex.vue]\n\u003Cscript lang=\"ts\" setup>\nimport { data } from '..\u002F..\u002F..\u002Fdata\u002Fgithub-projects.data'\n\nconst { frontmatter } = useData()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Csection class=\"space-y-16\">\n    \u003Ch1 class=\"text-6xl font-semibold\">\n      {{ frontmatter.title }}\n    \u003C\u002Fh1>\n\n    \u003Cdiv v-for=\"section in data\" :key=\"section.title\" class=\"space-y-20\">\n      \u003Csection class=\"space-y-10\">\n        \u003Ch2 class=\"text-4xl font-semibold\">\n          {{ section.title }}\n        \u003C\u002Fh2>\n\n        \u003CProjectCard\n          v-for=\"project in section.projects\"\n          :key=\"project.url\"\n          :project=\"project\"\n        \u002F>\n      \u003C\u002Fsection>\n    \u003C\u002Fdiv>\n\n    \u003Cdiv class=\"flex justify-center\">\n      \u003CButtonPrimary href=\"\u002F\">\n        Back to Home\n      \u003C\u002FButtonPrimary>\n    \u003C\u002Fdiv>\n  \u003C\u002Fsection>\n\u003C\u002Ftemplate>\n```\n\nThis component is straightforward. It iterates over each category of projects and displays them using the `ProjectCard` component. Additionally, a button leading back to the home page is included, consistent with other pages. The imported data is straightforward to consume due to its definition in the `github-projects.data.ts` file, minimizing the need for manipulation within the component. This methodology is preferable to maintain simplicity in the component and place logic at build time.\n\n![Our new projects page with GitHub projects](\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fshowcase-your-github-projects-on-your-vitepress-blog\u002Fvitepress-projects.png)\n\nWith this practical example, we now have a deeper understanding of the versatility and efficacy of **VitePress data loaders**. They even allow integration with a **headless CMS** to display your content or **a database** to access your data. The possibilities are truly limitless!\n",{"title":5,"description":2557},"create-a-blog-with-vitepress-and-vue-js-from-scratch",{"loc":2562,"images":2567},[2568,2569],{"loc":345},{"loc":2527},"series\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fshowcase-your-github-projects-on-your-vitepress-blog","b26V2LyH3_UXCV-Bn3ZneW3zCB01W66rllD0sOaL80c",{"overview":2573,"chapters":2809},{"id":2574,"title":2575,"body":2576,"contentId":2789,"date":2790,"description":2791,"extension":48,"github":2792,"meetTheInstructor":2795,"meta":2796,"navigation":273,"part":2560,"path":2797,"rawbody":2798,"robots":2560,"schemaOrg":2560,"seo":2799,"seriesSlug":2565,"sitemap":2800,"stem":2803,"subtitle":2804,"topics":2805,"__hash__":2808},"series\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch.md","Create a Blog with VitePress and Vue.js from Scratch",{"type":7,"value":2577,"toc":2786},[2578,2581,2595,2609,2744,2755,2763,2770,2773,2776,2780],[10,2579,2580],{},"Hello and welcome! 👋",[10,2582,2583,2584,2587,2588,2590,2591,2594],{},"You're about to embark on the \"Create a ",[14,2585,2586],{},"Blog"," with ",[14,2589,423],{}," and ",[14,2592,2593],{},"Vue.js"," from Scratch\" series!",[10,2596,2597,2598,2604,2605,2608],{},"Throughout this journey, we will construct a practical blog from the ground up using ",[332,2599,2602],{"href":2600,"rel":2601},"https:\u002F\u002Fvitepress.dev\u002F",[336],[14,2603,423],{},". We will explore a range of topics from initial configuration to deploying on ",[14,2606,2607],{},"Cloudflare Pages",", including:",[2610,2611,2612,2637,2647,2653,2666,2672,2682,2690,2700,2712,2729,2735],"ul",{},[1292,2613,2614,2617,2618,2621,2622,2590,2629,2636],{},[14,2615,2616],{},"Getting Started with VitePress: Project Setup and Essentials",": Learn to set up a fresh ",[14,2619,2620],{},"VitePress project"," by incorporating ",[332,2623,2626],{"href":2624,"rel":2625},"https:\u002F\u002Ftailwindcss.com\u002F",[336],[14,2627,2628],{},"Tailwind CSS",[332,2630,2633],{"href":2631,"rel":2632},"https:\u002F\u002Fgithub.com\u002Funplugin\u002Funplugin-vue-components",[336],[14,2634,2635],{},"unplugin-vue-components"," for an enhanced development process.",[1292,2638,2639,2642,2643],{},[14,2640,2641],{},"From Default to Custom: Building a VitePress Blog Theme",": We will entirely remove the default theme and create a personalized theme. ",[2644,2645,2646],"em",{},"You'll be surprised by its simplicity!",[1292,2648,2649,2652],{},[14,2650,2651],{},"Optimize Your VitePress Blog's Architecture Design",": Discover how to organize code and design your blog for scalability and maintainability.",[1292,2654,2655,2658,2659,916],{},[14,2656,2657],{},"Implementing Blog Index with VitePress and Tailwind CSS",": Create a list of blog posts. This will introduce ",[332,2660,2663],{"href":2661,"rel":2662},"https:\u002F\u002Fvitepress.dev\u002Fguide\u002Fdata-loading",[336],[14,2664,2665],{},"data loaders from VitePress",[1292,2667,2668,2671],{},[14,2669,2670],{},"Single Blog Rendering in VitePress with Tailwind Typography",": Create a page dedicated to reading each blog post.",[1292,2673,2674,2677,2678,2681],{},[14,2675,2676],{},"Deploy VitePress Blog Globally with Cloudflare Pages",": Integrate ",[14,2679,2680],{},"SEO metadata"," for improved search engine visibility, eliminating the need for manual updates.",[1292,2683,2684,2686,2687,2689],{},[14,2685,5],{},": Develop a page to display your ",[14,2688,358],{}," endeavors, extending the use of data loaders and demonstrating their flexibility.",[1292,2691,2692,2695,2696,2699],{},[14,2693,2694],{},"Creating Open Graph Images Automatically for Each Blog Post",": Efficiently create ",[14,2697,2698],{},"Open Graph images"," for each post, saving time and enhancing appeal.",[1292,2701,2702,2704,2705,2711],{},[14,2703,2676],{},": Seamlessly deploy your blog to ",[332,2706,2709],{"href":2707,"rel":2708},"https:\u002F\u002Fpages.cloudflare.com\u002F",[336],[14,2710,2607],{},", achieving this in just a few clicks!",[1292,2713,2714,2717,2718,2587,2721,2728],{},[14,2715,2716],{},"Ensure Blog Quality with Playwright Automated Testing",": Implement ",[14,2719,2720],{},"end-to-end testing",[332,2722,2725],{"href":2723,"rel":2724},"https:\u002F\u002Fplaywright.dev\u002F",[336],[14,2726,2727],{},"Playwright"," to ensure your blog functions as expected.",[1292,2730,2731,2734],{},[14,2732,2733],{},"An Internal Refactor for the Future Growth of our Blog",": Prepare your blog for future growth by refactoring the codebase, ensuring it remains maintainable and scalable.",[1292,2736,2737,2740,2741,2743],{},[14,2738,2739],{},"Migrating Our VitePress Blog to Tailwind CSS Version 4",": Upgrade our blog to the latest version of ",[14,2742,2628],{}," to leverage its new features and improvements.",[10,2745,2746,2747,2750,2751,2754],{},"By the conclusion, you will possess a fully operational and captivating ",[14,2748,2749],{},"blog",", allowing you to concentrate exclusively on producing ",[14,2752,2753],{},"content",", which is paramount. Simply write and publish, as the blog will autonomously manage the rest.",[339,2756,2757,2761],{},[342,2758],{"alt":2759,"src":2760},"Home Page of our Blog","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fdeploy-vitepress-blog-globally-with-cloudflare-pages\u002Fvitepress-home.png",[347,2762,2759],{},[10,2764,2765,2766,2769],{},"This series offers a detailed, step-by-step ",[14,2767,2768],{},"guide",". Rest assured, each aspect will be thoroughly elucidated, from selecting to implementing every feature. While each feature will be minimal and focused on the core, this does not mean we will forgo creating a visually pleasing and functional blog.",[10,2771,2772],{},"Should you have any inquiries, please feel free to engage in the comments section under each article.",[10,2774,2775],{},"I hope you find this series truly enjoyable! 🚀",[27,2777,2779],{"id":2778},"chapters","Chapters",[2781,2782],"series-chapters-list",{"className":2783},[2784,2785],"mx-auto","max-w-5xl",{"title":49,"searchDepth":63,"depth":63,"links":2787},[2788],{"id":2778,"depth":63,"text":2779},"43c95b33-041c-4108-ab98-0d21ef60ed7f","2024-10-10","Build a dynamic blog with VitePress and Vue.js from scratch. Learn setup, SEO, and deployment for a seamless blogging experience.",{"name":2793,"repository":2794},"garabit","barbapapazes\u002Fgarabit","I create this series because \u003Cstrong>VitePress\u003C\u002Fstrong> is way more powerful than it seems at the first glance. I was amazed by the \u003Cstrong>flexibility\u003C\u002Fstrong> and the \u003Cstrong>simplicity\u003C\u002Fstrong> of the tool while building my blog and wanted the community to know about it.",{},"\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch","---\ncontentId: 43c95b33-041c-4108-ab98-0d21ef60ed7f\ntitle: Create a Blog with VitePress and Vue.js from Scratch\nsubtitle: A new perspective on blogging with VitePress and Vue.js\ndescription: Build a dynamic blog with VitePress and Vue.js from scratch. Learn setup, SEO, and deployment for a seamless blogging experience.\ndate: 2024-10-10\ntopics:\n  - vuejs\n  - vitepress\n  - blog\ngithub:\n  name: garabit\n  repository: barbapapazes\u002Fgarabit\nmeetTheInstructor: I create this series because \u003Cstrong>VitePress\u003C\u002Fstrong> is way more powerful than it seems at the first glance. I was amazed by the \u003Cstrong>flexibility\u003C\u002Fstrong> and the \u003Cstrong>simplicity\u003C\u002Fstrong> of the tool while building my blog and wanted the community to know about it.\nseriesSlug: create-a-blog-with-vitepress-and-vue-js-from-scratch\n---\n\nHello and welcome! 👋\n\nYou're about to embark on the \"Create a **Blog** with **VitePress** and **Vue.js** from Scratch\" series!\n\nThroughout this journey, we will construct a practical blog from the ground up using [**VitePress**](https:\u002F\u002Fvitepress.dev\u002F). We will explore a range of topics from initial configuration to deploying on **Cloudflare Pages**, including:\n\n- **Getting Started with VitePress: Project Setup and Essentials**: Learn to set up a fresh **VitePress project** by incorporating [**Tailwind CSS**](https:\u002F\u002Ftailwindcss.com\u002F) and [**unplugin-vue-components**](https:\u002F\u002Fgithub.com\u002Funplugin\u002Funplugin-vue-components) for an enhanced development process.\n- **From Default to Custom: Building a VitePress Blog Theme**: We will entirely remove the default theme and create a personalized theme. _You'll be surprised by its simplicity!_\n- **Optimize Your VitePress Blog's Architecture Design**: Discover how to organize code and design your blog for scalability and maintainability.\n- **Implementing Blog Index with VitePress and Tailwind CSS**: Create a list of blog posts. This will introduce [**data loaders from VitePress**](https:\u002F\u002Fvitepress.dev\u002Fguide\u002Fdata-loading).\n- **Single Blog Rendering in VitePress with Tailwind Typography**: Create a page dedicated to reading each blog post.\n- **Deploy VitePress Blog Globally with Cloudflare Pages**: Integrate **SEO metadata** for improved search engine visibility, eliminating the need for manual updates.\n- **Showcase Your GitHub Projects on Your VitePress Blog**: Develop a page to display your **GitHub** endeavors, extending the use of data loaders and demonstrating their flexibility.\n- **Creating Open Graph Images Automatically for Each Blog Post**: Efficiently create **Open Graph images** for each post, saving time and enhancing appeal.\n- **Deploy VitePress Blog Globally with Cloudflare Pages**: Seamlessly deploy your blog to [**Cloudflare Pages**](https:\u002F\u002Fpages.cloudflare.com\u002F), achieving this in just a few clicks!\n- **Ensure Blog Quality with Playwright Automated Testing**: Implement **end-to-end testing** with [**Playwright**](https:\u002F\u002Fplaywright.dev\u002F) to ensure your blog functions as expected.\n- **An Internal Refactor for the Future Growth of our Blog**: Prepare your blog for future growth by refactoring the codebase, ensuring it remains maintainable and scalable.\n- **Migrating Our VitePress Blog to Tailwind CSS Version 4**: Upgrade our blog to the latest version of **Tailwind CSS** to leverage its new features and improvements.\n\nBy the conclusion, you will possess a fully operational and captivating **blog**, allowing you to concentrate exclusively on producing **content**, which is paramount. Simply write and publish, as the blog will autonomously manage the rest.\n\n![Home Page of our Blog](\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fdeploy-vitepress-blog-globally-with-cloudflare-pages\u002Fvitepress-home.png)\n\nThis series offers a detailed, step-by-step **guide**. Rest assured, each aspect will be thoroughly elucidated, from selecting to implementing every feature. While each feature will be minimal and focused on the core, this does not mean we will forgo creating a visually pleasing and functional blog.\n\nShould you have any inquiries, please feel free to engage in the comments section under each article.\n\nI hope you find this series truly enjoyable! 🚀\n\n## Chapters\n\n::series-chapters-list\n---\nclass: mx-auto max-w-5xl\n---\n::\n",{"title":2575,"description":2791},{"loc":2797,"images":2801},[2802],{"loc":2760},"series\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch","A new perspective on blogging with VitePress and Vue.js",[2806,2807,2749],"vuejs","vitepress","H9cubHgLKM0Siblzkwf7mDsFVYr2CLbh_ciFOpQrSVk",[2810,2816,2822,2828,2834,2840,2847,2849,2855,2861,2867,2874],{"contentId":2811,"title":2616,"description":2812,"path":2813,"part":56,"github":2814,"topics":2560},"b1b99d95-ac6d-4f25-a121-0851988102a2","From setup to styling with Tailwind CSS and automatic Vue imports, build your content-driven site effortlessly.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fgetting-started-with-vitepress-project-setup-and-essentials",{"branch":2815},"01.project-initialization",{"contentId":2817,"title":2641,"description":2818,"path":2819,"part":63,"github":2820,"topics":2560},"172f2a41-2f7c-44e9-855d-322adc536279","Step-by-step VitePress theme customization: guide to building a unique theme layout, adding Markdown content, and removing defaults.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Ffrom-default-to-custom-building-a-vitepress-blog-theme",{"branch":2821},"02.the-basics-for-a-custom-theme",{"contentId":2823,"title":2651,"description":2824,"path":2825,"part":77,"github":2826,"topics":2560},"900d11a5-ff68-4cc9-8ace-66a5cb1577fa","Discover how to optimize your VitePress blog's architecture design with scalable solutions and efficient Vite plugin integration.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Foptimize-your-vitepress-blog-architecture-design",{"branch":2827},"03.define-the-design-of-the-blog-architecture",{"contentId":2829,"title":2657,"description":2830,"path":2831,"part":88,"github":2832,"topics":2560},"4d93a3c5-f3ff-4ff6-a569-5234ef805850","Learn to create a list of blog articles using VitePress, a crucial feature for any content-centric website. Utilize data loaders to load articles.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fimplementing-blog-index-with-vitepress-and-tailwind-css",{"branch":2833},"04.comprehensive-guide-to-listing-blog-articles",{"contentId":2835,"title":2670,"description":2836,"path":2837,"part":99,"github":2838,"topics":2560},"15b9a49c-b9fb-4d76-a08d-2acaf55ff205","Enhance your VitePress blog with Tailwind Typography. Learn to render markdown beautifully with syntax highlights.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fsingle-blog-rendering-in-vitepress-with-tailwind-typography",{"branch":2839},"05.read-a-single-blog-article",{"contentId":2841,"title":2842,"description":2843,"path":2844,"part":270,"github":2845,"topics":2560},"66af9aaf-d6d3-4151-a51b-806835988340","Enhance Website Visibility: SEO Metadata and Sitemap","Enhance website traffic through strategic SEO metadata and sitemaps for improved indexing. Learn how to automate metadata generation for each page.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fenhance-website-visibility-seo-metadata-and-sitemap",{"branch":2846},"06.seo-metadata-and-sitemap",{"contentId":2555,"title":5,"description":2557,"path":2562,"part":277,"github":2848,"topics":2560},{"branch":2559},{"contentId":2850,"title":2694,"description":2851,"path":2852,"part":301,"github":2853,"topics":2560},"c76a349e-a495-4890-ab05-3e8b6bb90add","Learn how to dynamically generate Open Graph images for each blog post, enhancing the visual appeal when sharing content on social media.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fcreating-open-graph-images-automatically-for-each-blog-post",{"branch":2854},"08.automatically-generated-open-graph-images",{"contentId":2856,"title":2676,"description":2857,"path":2858,"part":311,"github":2859,"topics":2560},"c05ae463-c5ae-4c43-872d-bb05263c7f74","Deploy the blog to Cloudflare Pages for global accessibility. Discover how to deploy the blog to Cloudflare Pages and share it worldwide with ease.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fdeploy-vitepress-blog-globally-with-cloudflare-pages",{"branch":2860},"09.share-the-blog-globally",{"contentId":2862,"title":2716,"description":2863,"path":2864,"part":321,"github":2865,"topics":2560},"aa5392e0-6287-4673-9365-34313f0af1fa","Enhance web development with Playwright-induced automated testing. Elevate blog quality through comprehensive end-to-end and SEO tests.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fensure-blog-quality-with-playwright-automated-testing",{"branch":2866},"10.automate-testing",{"contentId":2868,"title":2869,"description":2870,"path":2871,"part":661,"github":2872,"topics":2560},"5b1b6117-14f0-4f1d-ba13-5b3583f341bf","An Internal Refactor for the Future Growth of Our Blog","Prepare your blog for future growth by refactoring the codebase to ensure it remains maintainable and scalable.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fan-internal-refactor-for-the-future-growth-of-our-blog",{"branch":2873},"11.internal-refactor",{"contentId":2875,"title":2739,"description":2876,"path":2877,"part":669,"github":2878,"topics":2560},"3499bbd1-20a6-43f0-9bb7-be1da2bb6eac","A step-by-step guide on upgrading our VitePress blog to Tailwind CSS 4.0 to leverage its latest features and improvements.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fmigrating-our-vitepress-blog-to-tailwind-css-version-4",{"branch":2879},"12.migration-to-tailwind-css-4",1795016692533]