[{"data":1,"prerenderedAt":2494},["ShallowReactive",2],{"series-\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fimplementing-blog-index-with-vitepress-and-tailwind-css":3,"series-context-\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch":2190},{"id":4,"title":5,"body":6,"contentId":2174,"date":2175,"description":2176,"extension":493,"github":2177,"meetTheInstructor":2179,"meta":2180,"navigation":407,"part":105,"path":2181,"rawbody":2182,"robots":2179,"schemaOrg":2179,"seo":2183,"seriesSlug":2184,"sitemap":2185,"stem":2188,"subtitle":2179,"topics":2179,"__hash__":2189},"series\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fimplementing-blog-index-with-vitepress-and-tailwind-css.md","Implementing Blog Index with VitePress and Tailwind CSS",{"type":7,"value":8,"toc":2162},"minimark",[9,18,23,35,115,118,126,131,146,152,177,184,215,226,274,284,320,324,335,364,370,452,460,463,467,489,536,539,549,560,564,575,674,677,687,823,842,846,859,872,886,969,978,988,994,1001,1099,1105,1250,1268,1272,1279,1282,1287,1463,1466,1471,1475,1478,1488,1717,1723,1997,2003,2134,2138,2149,2158],[10,11,12,13,17],"p",{},"Before diving into the core task, we must set up ",[14,15,16],"strong",{},"Tailwind CSS",". This step, while straightforward, is essential for styling our blog effectively.",[19,20,22],"h2",{"id":21},"tailwind-css-configuration","Tailwind CSS configuration",[10,24,25,26,30,31,34],{},"We need to direct Tailwind CSS to the location of our files. In the ",[27,28,29],"code",{},"tailwind.config.cjs"," file at the project root, utilize the ",[27,32,33],{},"content"," key to specify which files to analyze to generate the necessary CSS classes.",[36,37,42],"pre",{"className":38,"code":39,"filename":29,"language":40,"meta":41,"style":41},"language-js shiki shiki-themes github-light github-light github-dark","\u002F** @type {import('tailwindcss').Config} *\u002F\nmodule.exports = {\n  content: ['.\u002Fsrc\u002F**\u002F*.md', '.\u002F.vitepress\u002Ftheme\u002F**\u002F*.{vue,ts}'],\n  \u002F\u002F ...\n}\n","js","",[27,43,44,64,84,103,109],{"__ignoreMap":41},[45,46,49,53,57,61],"span",{"class":47,"line":48},"line",1,[45,50,52],{"class":51},"sCsY4","\u002F** ",[45,54,56],{"class":55},"s8jYJ","@type",[45,58,60],{"class":59},"snPdu"," {import('tailwindcss').Config}",[45,62,63],{"class":51}," *\u002F\n",[45,65,67,71,75,78,81],{"class":47,"line":66},2,[45,68,70],{"class":69},"sBjJW","module",[45,72,74],{"class":73},"sxrX7",".",[45,76,77],{"class":69},"exports",[45,79,80],{"class":55}," =",[45,82,83],{"class":73}," {\n",[45,85,87,90,94,97,100],{"class":47,"line":86},3,[45,88,89],{"class":73},"  content: [",[45,91,93],{"class":92},"sIIMD","'.\u002Fsrc\u002F**\u002F*.md'",[45,95,96],{"class":73},", ",[45,98,99],{"class":92},"'.\u002F.vitepress\u002Ftheme\u002F**\u002F*.{vue,ts}'",[45,101,102],{"class":73},"],\n",[45,104,106],{"class":47,"line":105},4,[45,107,108],{"class":51},"  \u002F\u002F ...\n",[45,110,112],{"class":47,"line":111},5,[45,113,114],{"class":73},"}\n",[10,116,117],{},"We instruct Tailwind CSS to scan both Markdown files and all Vue and TypeScript files in the theme directory.",[119,120,123],"callout",{"color":121,"icon":122},"info","i-ph-info-duotone",[10,124,125],{},"Monitoring Markdown files is vital since HTML can exist within them, and components can also be included.",[127,128,130],"h3",{"id":129},"integrating-prettier-with-tailwind-css-plugin","Integrating Prettier with Tailwind CSS plugin",[10,132,133,134,141,142,145],{},"Additionally, we will configure ",[135,136,140],"a",{"href":137,"rel":138},"https:\u002F\u002Fprettier.io\u002F",[139],"nofollow","Prettier"," for code formatting and implement the Prettier Tailwind CSS ",[14,143,144],{},"plugin"," to automatically sort classes.",[10,147,148,149,151],{},"To install Prettier and the ",[14,150,144],{},", execute:",[36,153,158],{"className":154,"code":155,"filename":156,"language":157,"meta":41,"style":41},"language-sh shiki shiki-themes github-light github-light github-dark","pnpm add -D prettier prettier-plugin-tailwindcss\n","terminal","sh",[27,159,160],{"__ignoreMap":41},[45,161,162,165,168,171,174],{"class":47,"line":48},[45,163,164],{"class":59},"pnpm",[45,166,167],{"class":92}," add",[45,169,170],{"class":69}," -D",[45,172,173],{"class":92}," prettier",[45,175,176],{"class":92}," prettier-plugin-tailwindcss\n",[10,178,179,180,183],{},"Create a ",[27,181,182],{},".prettierrc"," file at the project's root with the following configuration:",[36,185,190],{"className":186,"code":187,"filename":188,"language":189,"meta":41,"style":41},"language-json shiki shiki-themes github-light github-light github-dark","{\n  \"plugins\": [\"prettier-plugin-tailwindcss\"]\n}\n","Example","json",[27,191,192,197,211],{"__ignoreMap":41},[45,193,194],{"class":47,"line":48},[45,195,196],{"class":73},"{\n",[45,198,199,202,205,208],{"class":47,"line":66},[45,200,201],{"class":69},"  \"plugins\"",[45,203,204],{"class":73},": [",[45,206,207],{"class":92},"\"prettier-plugin-tailwindcss\"",[45,209,210],{"class":73},"]\n",[45,212,213],{"class":47,"line":86},[45,214,114],{"class":73},[10,216,217,218,221,222,225],{},"If you're using ",[14,219,220],{},"Visual Studio Code",", include the following in ",[27,223,224],{},".vscode\u002Fsettings.json"," to enable auto-formatting on save:",[36,227,229],{"className":186,"code":228,"filename":224,"language":189,"meta":41,"style":41},"{\n  \"prettier.enable\": true,\n  \"editor.formatOnSave\": true,\n  \"editor.defaultFormatter\": \"esbenp.prettier-vscode\"\n}\n",[27,230,231,235,249,260,270],{"__ignoreMap":41},[45,232,233],{"class":47,"line":48},[45,234,196],{"class":73},[45,236,237,240,243,246],{"class":47,"line":66},[45,238,239],{"class":69},"  \"prettier.enable\"",[45,241,242],{"class":73},": ",[45,244,245],{"class":69},"true",[45,247,248],{"class":73},",\n",[45,250,251,254,256,258],{"class":47,"line":86},[45,252,253],{"class":69},"  \"editor.formatOnSave\"",[45,255,242],{"class":73},[45,257,245],{"class":69},[45,259,248],{"class":73},[45,261,262,265,267],{"class":47,"line":105},[45,263,264],{"class":69},"  \"editor.defaultFormatter\"",[45,266,242],{"class":73},[45,268,269],{"class":92},"\"esbenp.prettier-vscode\"\n",[45,271,272],{"class":47,"line":111},[45,273,114],{"class":73},[10,275,276,277,280,281,283],{},"Add a script in ",[27,278,279],{},"package.json"," to format files using ",[14,282,140],{},":",[36,285,287],{"className":186,"code":286,"filename":279,"language":189,"meta":41,"style":41},"{\n  \"scripts\": {\n    \"format\": \"prettier --write .\"\n  }\n}\n",[27,288,289,293,301,311,316],{"__ignoreMap":41},[45,290,291],{"class":47,"line":48},[45,292,196],{"class":73},[45,294,295,298],{"class":47,"line":66},[45,296,297],{"class":69},"  \"scripts\"",[45,299,300],{"class":73},": {\n",[45,302,303,306,308],{"class":47,"line":86},[45,304,305],{"class":69},"    \"format\"",[45,307,242],{"class":73},[45,309,310],{"class":92},"\"prettier --write .\"\n",[45,312,313],{"class":47,"line":105},[45,314,315],{"class":73},"  }\n",[45,317,318],{"class":47,"line":111},[45,319,114],{"class":73},[127,321,323],{"id":322},"connecting-tailwind-css-to-the-project","Connecting Tailwind CSS to the project",[10,325,326,327,330,331,334],{},"Finally, we need to link our project with the CSS generated by Tailwind CSS. In ",[27,328,329],{},".vitepress\u002Ftheme\u002Fstyles",", create an ",[27,332,333],{},"app.css"," file and append the Tailwind CSS directives:",[36,336,340],{"className":337,"code":338,"filename":333,"language":339,"meta":41,"style":41},"language-css shiki shiki-themes github-light github-light github-dark","@tailwind base;\n@tailwind components;\n@tailwind utilities;\n","css",[27,341,342,350,357],{"__ignoreMap":41},[45,343,344,347],{"class":47,"line":48},[45,345,346],{"class":55},"@tailwind",[45,348,349],{"class":73}," base;\n",[45,351,352,354],{"class":47,"line":66},[45,353,346],{"class":55},[45,355,356],{"class":73}," components;\n",[45,358,359,361],{"class":47,"line":86},[45,360,346],{"class":55},[45,362,363],{"class":73}," utilities;\n",[10,365,366,367,283],{},"Then, import this file into ",[27,368,369],{},".vitepress\u002Ftheme\u002Findex.ts",[36,371,375],{"className":372,"code":373,"filename":369,"language":374,"meta":41,"style":41},"language-ts shiki shiki-themes github-light github-light github-dark has-diff","import { Theme } from 'vitepress'\nimport Layout from '.\u002FLayout.vue'\n\nimport '.\u002Fstyles\u002Fapp.css' \u002F\u002F [!code ++]\n\nexport default {\n  Layout,\n} satisfies Theme\n","ts",[27,376,377,391,403,409,419,423,434,440],{"__ignoreMap":41},[45,378,379,382,385,388],{"class":47,"line":48},[45,380,381],{"class":55},"import",[45,383,384],{"class":73}," { Theme } ",[45,386,387],{"class":55},"from",[45,389,390],{"class":92}," 'vitepress'\n",[45,392,393,395,398,400],{"class":47,"line":66},[45,394,381],{"class":55},[45,396,397],{"class":73}," Layout ",[45,399,387],{"class":55},[45,401,402],{"class":92}," '.\u002FLayout.vue'\n",[45,404,405],{"class":47,"line":86},[45,406,408],{"emptyLinePlaceholder":407},true,"\n",[45,410,414,416],{"class":411,"line":105},[47,412,413],"diff","add",[45,415,381],{"class":55},[45,417,418],{"class":92}," '.\u002Fstyles\u002Fapp.css'",[45,420,421],{"class":47,"line":111},[45,422,408],{"emptyLinePlaceholder":407},[45,424,426,429,432],{"class":47,"line":425},6,[45,427,428],{"class":55},"export",[45,430,431],{"class":55}," default",[45,433,83],{"class":73},[45,435,437],{"class":47,"line":436},7,[45,438,439],{"class":73},"  Layout,\n",[45,441,443,446,449],{"class":47,"line":442},8,[45,444,445],{"class":73},"} ",[45,447,448],{"class":55},"satisfies",[45,450,451],{"class":59}," Theme\n",[10,453,454,455,74],{},"Importing a CSS file directly within a TypeScript file poses no issues as ",[135,456,459],{"href":457,"rel":458},"https:\u002F\u002Fvite.dev\u002Fguide\u002Ffeatures.html#css",[139],"Vite seamlessly handles it",[10,461,462],{},"Now, we're prepared to start styling our blog!",[19,464,466],{"id":465},"developing-the-blog-page","Developing the blog page",[10,468,469,470,473,474,477,478,481,482,484,485,488],{},"We require a page to display all our blog articles. As discussed in earlier articles, ",[14,471,472],{},"VitePress"," treats Markdown files in the ",[27,475,476],{},"src"," directory as pages. Thus, we'll create a ",[27,479,480],{},"blog.md"," file in the ",[27,483,476],{}," directory. This page will map to the ",[14,486,487],{},"\u002Fblog"," route.",[36,490,494],{"className":491,"code":492,"filename":480,"language":493,"meta":41,"style":41},"language-md shiki shiki-themes github-light github-light github-dark","---\nlayout: blog\ntitle: Blog\ndescription: The latest articles, tutorials, and resources on web development, programming, and more.\n---\n","md",[27,495,496,501,512,522,532],{"__ignoreMap":41},[45,497,498],{"class":47,"line":48},[45,499,500],{"class":73},"---\n",[45,502,503,507,509],{"class":47,"line":66},[45,504,506],{"class":505},"sovSZ","layout",[45,508,242],{"class":73},[45,510,511],{"class":92},"blog\n",[45,513,514,517,519],{"class":47,"line":86},[45,515,516],{"class":505},"title",[45,518,242],{"class":73},[45,520,521],{"class":92},"Blog\n",[45,523,524,527,529],{"class":47,"line":105},[45,525,526],{"class":505},"description",[45,528,242],{"class":73},[45,530,531],{"class":92},"The latest articles, tutorials, and resources on web development, programming, and more.\n",[45,533,534],{"class":47,"line":111},[45,535,500],{"class":73},[10,537,538],{},"The body remains empty to allow the component to manage the page structure. This component will include:",[540,541,542,546],"ul",{},[543,544,545],"li",{},"A comprehensive list of articles",[543,547,548],{},"A navigation button to return to the homepage",[119,550,553],{"color":551,"icon":552},"success","i-ph-lightbulb-duotone",[10,554,555,556],{},"Determine content placement by considering theme-neutral content. For instance, is the article list part of the theme or the content? A theme may display this list in various formats, column, grid, or carousel, which the theme dictates. Content must remain theme-agnostic. ",[557,558,559],"em",{},"There is some exception to this rule, especially for inlined content.",[19,561,563],{"id":562},"routing-the-blog-page-to-the-component","Routing the blog page to the component",[10,565,566,567,570,571,574],{},"Within ",[27,568,569],{},".vitepress\u002Ftheme\u002Fpages",", create the ",[27,572,573],{},"Blog\u002FBlogIndex.vue"," component:",[36,576,580],{"className":577,"code":578,"filename":573,"language":579,"meta":41,"style":41},"language-vue shiki shiki-themes github-light github-light github-dark","\u003Cscript lang=\"ts\" setup>\n\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Csection>\n    \u003Ch1>Blog\u003C\u002Fh1>\n  \u003C\u002Fsection>\n\u003C\u002Ftemplate>\n","vue",[27,581,582,605,609,618,622,631,641,656,665],{"__ignoreMap":41},[45,583,584,587,590,593,596,599,602],{"class":47,"line":48},[45,585,586],{"class":73},"\u003C",[45,588,589],{"class":505},"script",[45,591,592],{"class":59}," lang",[45,594,595],{"class":73},"=",[45,597,598],{"class":92},"\"ts\"",[45,600,601],{"class":59}," setup",[45,603,604],{"class":73},">\n",[45,606,607],{"class":47,"line":66},[45,608,408],{"emptyLinePlaceholder":407},[45,610,611,614,616],{"class":47,"line":86},[45,612,613],{"class":73},"\u003C\u002F",[45,615,589],{"class":505},[45,617,604],{"class":73},[45,619,620],{"class":47,"line":105},[45,621,408],{"emptyLinePlaceholder":407},[45,623,624,626,629],{"class":47,"line":111},[45,625,586],{"class":73},[45,627,628],{"class":505},"template",[45,630,604],{"class":73},[45,632,633,636,639],{"class":47,"line":425},[45,634,635],{"class":73},"  \u003C",[45,637,638],{"class":505},"section",[45,640,604],{"class":73},[45,642,643,646,649,652,654],{"class":47,"line":436},[45,644,645],{"class":73},"    \u003C",[45,647,648],{"class":505},"h1",[45,650,651],{"class":73},">Blog\u003C\u002F",[45,653,648],{"class":505},[45,655,604],{"class":73},[45,657,658,661,663],{"class":47,"line":442},[45,659,660],{"class":73},"  \u003C\u002F",[45,662,638],{"class":505},[45,664,604],{"class":73},[45,666,668,670,672],{"class":47,"line":667},9,[45,669,613],{"class":73},[45,671,628],{"class":505},[45,673,604],{"class":73},[10,675,676],{},"This component structures the page. It employs the correlated Markdown file to present the title and articles.",[10,678,679,680,683,684,686],{},"In ",[27,681,682],{},"Layout.vue",", link the layout to the component by extracting the ",[27,685,506],{}," key from the current file's frontmatter for appropriate component display.",[36,688,690],{"className":577,"code":689,"filename":682,"language":579,"meta":41,"style":41},"\u003Cscript lang=\"ts\" setup>\nconst { frontmatter } = useData()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Cdiv>\n    \u003Cmain>\n      \u003CBlogIndex v-if=\"frontmatter.layout === 'blog'\" \u002F>\n    \u003C\u002Fmain>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n",[27,691,692,708,730,738,742,750,759,768,796,805,814],{"__ignoreMap":41},[45,693,694,696,698,700,702,704,706],{"class":47,"line":48},[45,695,586],{"class":73},[45,697,589],{"class":505},[45,699,592],{"class":59},[45,701,595],{"class":73},[45,703,598],{"class":92},[45,705,601],{"class":59},[45,707,604],{"class":73},[45,709,710,713,716,719,722,724,727],{"class":47,"line":66},[45,711,712],{"class":55},"const",[45,714,715],{"class":73}," { ",[45,717,718],{"class":69},"frontmatter",[45,720,721],{"class":73}," } ",[45,723,595],{"class":55},[45,725,726],{"class":59}," useData",[45,728,729],{"class":73},"()\n",[45,731,732,734,736],{"class":47,"line":86},[45,733,613],{"class":73},[45,735,589],{"class":505},[45,737,604],{"class":73},[45,739,740],{"class":47,"line":105},[45,741,408],{"emptyLinePlaceholder":407},[45,743,744,746,748],{"class":47,"line":111},[45,745,586],{"class":73},[45,747,628],{"class":505},[45,749,604],{"class":73},[45,751,752,754,757],{"class":47,"line":425},[45,753,635],{"class":73},[45,755,756],{"class":505},"div",[45,758,604],{"class":73},[45,760,761,763,766],{"class":47,"line":436},[45,762,645],{"class":73},[45,764,765],{"class":505},"main",[45,767,604],{"class":73},[45,769,770,773,776,779,781,784,787,790,793],{"class":47,"line":442},[45,771,772],{"class":73},"      \u003C",[45,774,775],{"class":505},"BlogIndex",[45,777,778],{"class":55}," v-if",[45,780,595],{"class":73},[45,782,783],{"class":92},"\"",[45,785,786],{"class":73},"frontmatter.layout ",[45,788,789],{"class":55},"===",[45,791,792],{"class":92}," 'blog'\"",[45,794,795],{"class":73}," \u002F>\n",[45,797,798,801,803],{"class":47,"line":667},[45,799,800],{"class":73},"    \u003C\u002F",[45,802,765],{"class":505},[45,804,604],{"class":73},[45,806,808,810,812],{"class":47,"line":807},10,[45,809,660],{"class":73},[45,811,756],{"class":505},[45,813,604],{"class":73},[45,815,817,819,821],{"class":47,"line":816},11,[45,818,613],{"class":73},[45,820,628],{"class":505},[45,822,604],{"class":73},[10,824,825,826,828,829,831,832,834,835,837,838,841],{},"Now, navigating to the ",[14,827,487],{}," route displays the ",[27,830,775],{}," component as VitePress loads the ",[27,833,480],{}," file, exposing its frontmatter to ",[27,836,682],{}," through the ",[27,839,840],{},"useData"," function.",[19,843,845],{"id":844},"loading-all-articles","Loading all articles",[10,847,848,849,852,853,858],{},"Now comes the exciting part! We'll load all articles from the ",[14,850,851],{},"src\u002Fblog"," directory. Employing ",[135,854,857],{"href":855,"rel":856},"https:\u002F\u002Fvitepress.dev\u002Fguide\u002Fdata-loading",[139],"VitePress data loaders",", this can be achieved with minimal code and no runtime burden. ✨",[119,860,861],{"color":121,"icon":122},[10,862,863,864,866,867,74],{},"Ensure the presence of some Markdown files in the ",[27,865,851],{}," directory. You can copy them from the ",[135,868,871],{"href":869,"rel":870},"https:\u002F\u002Fgithub.com\u002Fbarbapapazes\u002Fgarabit\u002Ftree\u002Fmain\u002Fsrc\u002Fblog",[139],"GitHub repository",[10,873,874,875,878,879,570,882,885],{},"In a ",[27,876,877],{},"data"," directory within ",[27,880,881],{},".vitepress",[27,883,884],{},"blog.data.ts"," file:",[36,887,890],{"className":888,"code":889,"filename":884,"language":374,"meta":41,"style":41},"language-ts shiki shiki-themes github-light github-light github-dark","import type { ContentData } from 'vitepress'\nimport { createContentLoader } from 'vitepress'\n\ndeclare const data: ContentData[]\nexport { data }\n\nexport default createContentLoader('blog\u002F*.md')\n",[27,891,892,906,917,921,940,947,951],{"__ignoreMap":41},[45,893,894,896,899,902,904],{"class":47,"line":48},[45,895,381],{"class":55},[45,897,898],{"class":55}," type",[45,900,901],{"class":73}," { ContentData } ",[45,903,387],{"class":55},[45,905,390],{"class":92},[45,907,908,910,913,915],{"class":47,"line":66},[45,909,381],{"class":55},[45,911,912],{"class":73}," { createContentLoader } ",[45,914,387],{"class":55},[45,916,390],{"class":92},[45,918,919],{"class":47,"line":86},[45,920,408],{"emptyLinePlaceholder":407},[45,922,923,926,929,932,934,937],{"class":47,"line":105},[45,924,925],{"class":55},"declare",[45,927,928],{"class":55}," const",[45,930,931],{"class":69}," data",[45,933,283],{"class":55},[45,935,936],{"class":59}," ContentData",[45,938,939],{"class":73},"[]\n",[45,941,942,944],{"class":47,"line":111},[45,943,428],{"class":55},[45,945,946],{"class":73}," { data }\n",[45,948,949],{"class":47,"line":425},[45,950,408],{"emptyLinePlaceholder":407},[45,952,953,955,957,960,963,966],{"class":47,"line":436},[45,954,428],{"class":55},[45,956,431],{"class":55},[45,958,959],{"class":59}," createContentLoader",[45,961,962],{"class":73},"(",[45,964,965],{"class":92},"'blog\u002F*.md'",[45,967,968],{"class":73},")\n",[119,970,971],{"color":121,"icon":122},[10,972,973,974,977],{},"Ensure the extension ",[27,975,976],{},".data.ts"," is used; it's crucial for functionality.",[10,979,980,981,983,984,987],{},"What's happening here? ",[14,982,472],{}," anticipates local ",[14,985,986],{},"Markdown"," file loading, providing a helper function for the task. Simply specify the directory.",[10,989,990,991,993],{},"The default type may be incorrect due to server transformation before data access. Export a custom type via the ",[27,992,877],{}," variable for correct imports.",[10,995,996,997,1000],{},"Load this module in the ",[27,998,999],{},"BlogIndex.vue"," component and render it to view the result:",[36,1002,1004],{"className":577,"code":1003,"filename":999,"language":579,"meta":41,"style":41},"\u003Cscript lang=\"ts\" setup>\nimport { data } from '..\u002F..\u002F..\u002Fdata\u002Fblog.data'\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Csection>\n    \u003Ch1>Blog\u003C\u002Fh1>\n\n    {{ data }}\n  \u003C\u002Fsection>\n\u003C\u002Ftemplate>\n",[27,1005,1006,1022,1034,1042,1046,1054,1062,1074,1078,1083,1091],{"__ignoreMap":41},[45,1007,1008,1010,1012,1014,1016,1018,1020],{"class":47,"line":48},[45,1009,586],{"class":73},[45,1011,589],{"class":505},[45,1013,592],{"class":59},[45,1015,595],{"class":73},[45,1017,598],{"class":92},[45,1019,601],{"class":59},[45,1021,604],{"class":73},[45,1023,1024,1026,1029,1031],{"class":47,"line":66},[45,1025,381],{"class":55},[45,1027,1028],{"class":73}," { data } ",[45,1030,387],{"class":55},[45,1032,1033],{"class":92}," '..\u002F..\u002F..\u002Fdata\u002Fblog.data'\n",[45,1035,1036,1038,1040],{"class":47,"line":86},[45,1037,613],{"class":73},[45,1039,589],{"class":505},[45,1041,604],{"class":73},[45,1043,1044],{"class":47,"line":105},[45,1045,408],{"emptyLinePlaceholder":407},[45,1047,1048,1050,1052],{"class":47,"line":111},[45,1049,586],{"class":73},[45,1051,628],{"class":505},[45,1053,604],{"class":73},[45,1055,1056,1058,1060],{"class":47,"line":425},[45,1057,635],{"class":73},[45,1059,638],{"class":505},[45,1061,604],{"class":73},[45,1063,1064,1066,1068,1070,1072],{"class":47,"line":436},[45,1065,645],{"class":73},[45,1067,648],{"class":505},[45,1069,651],{"class":73},[45,1071,648],{"class":505},[45,1073,604],{"class":73},[45,1075,1076],{"class":47,"line":442},[45,1077,408],{"emptyLinePlaceholder":407},[45,1079,1080],{"class":47,"line":667},[45,1081,1082],{"class":73},"    {{ data }}\n",[45,1084,1085,1087,1089],{"class":47,"line":807},[45,1086,660],{"class":73},[45,1088,638],{"class":505},[45,1090,604],{"class":73},[45,1092,1093,1095,1097],{"class":47,"line":816},[45,1094,613],{"class":73},[45,1096,628],{"class":505},[45,1098,604],{"class":73},[10,1100,1101,1102,1104],{},"Data output is an array of objects, each representing a ",[14,1103,986],{}," file. You can view each file's frontmatter and URL:",[36,1106,1108],{"className":186,"code":1107,"filename":188,"language":189,"meta":41,"style":41},"[\n  {\n    \"frontmatter\": {\n      \"title\": \"Getting Started with Vue 3 and Vite\",\n      \"description\": \"Learn how to set up a new Vue 3 project with Vite, the fast build tool for modern web development. Explore the basics of Vue 3, including the Composition API, reactivity, components, and more.\",\n      \"date\": \"2024-09-14T00:00:00.000Z\"\n    },\n    \"url\": \"\u002Fblog\u002Fgetting-started-with-vue3-and-vite.html\"\n  },\n  {\n    \"frontmatter\": {\n      \"title\": \"Getting Started with Laravel\",\n      \"description\": \"Learn how to set up a new Laravel project and build a simple web application. Explore the basics of Laravel, including routing, views, controllers, and more.\",\n      \"date\": \"2024-10-14T00:00:00.000Z\"\n    },\n    \"url\": \"\u002Fblog\u002Fgetting-started-wth-laravel.html\"\n  }\n]\n",[27,1109,1110,1115,1120,1127,1139,1151,1161,1166,1176,1181,1185,1191,1203,1215,1225,1230,1240,1245],{"__ignoreMap":41},[45,1111,1112],{"class":47,"line":48},[45,1113,1114],{"class":73},"[\n",[45,1116,1117],{"class":47,"line":66},[45,1118,1119],{"class":73},"  {\n",[45,1121,1122,1125],{"class":47,"line":86},[45,1123,1124],{"class":69},"    \"frontmatter\"",[45,1126,300],{"class":73},[45,1128,1129,1132,1134,1137],{"class":47,"line":105},[45,1130,1131],{"class":69},"      \"title\"",[45,1133,242],{"class":73},[45,1135,1136],{"class":92},"\"Getting Started with Vue 3 and Vite\"",[45,1138,248],{"class":73},[45,1140,1141,1144,1146,1149],{"class":47,"line":111},[45,1142,1143],{"class":69},"      \"description\"",[45,1145,242],{"class":73},[45,1147,1148],{"class":92},"\"Learn how to set up a new Vue 3 project with Vite, the fast build tool for modern web development. Explore the basics of Vue 3, including the Composition API, reactivity, components, and more.\"",[45,1150,248],{"class":73},[45,1152,1153,1156,1158],{"class":47,"line":425},[45,1154,1155],{"class":69},"      \"date\"",[45,1157,242],{"class":73},[45,1159,1160],{"class":92},"\"2024-09-14T00:00:00.000Z\"\n",[45,1162,1163],{"class":47,"line":436},[45,1164,1165],{"class":73},"    },\n",[45,1167,1168,1171,1173],{"class":47,"line":442},[45,1169,1170],{"class":69},"    \"url\"",[45,1172,242],{"class":73},[45,1174,1175],{"class":92},"\"\u002Fblog\u002Fgetting-started-with-vue3-and-vite.html\"\n",[45,1177,1178],{"class":47,"line":667},[45,1179,1180],{"class":73},"  },\n",[45,1182,1183],{"class":47,"line":807},[45,1184,1119],{"class":73},[45,1186,1187,1189],{"class":47,"line":816},[45,1188,1124],{"class":69},[45,1190,300],{"class":73},[45,1192,1194,1196,1198,1201],{"class":47,"line":1193},12,[45,1195,1131],{"class":69},[45,1197,242],{"class":73},[45,1199,1200],{"class":92},"\"Getting Started with Laravel\"",[45,1202,248],{"class":73},[45,1204,1206,1208,1210,1213],{"class":47,"line":1205},13,[45,1207,1143],{"class":69},[45,1209,242],{"class":73},[45,1211,1212],{"class":92},"\"Learn how to set up a new Laravel project and build a simple web application. Explore the basics of Laravel, including routing, views, controllers, and more.\"",[45,1214,248],{"class":73},[45,1216,1218,1220,1222],{"class":47,"line":1217},14,[45,1219,1155],{"class":69},[45,1221,242],{"class":73},[45,1223,1224],{"class":92},"\"2024-10-14T00:00:00.000Z\"\n",[45,1226,1228],{"class":47,"line":1227},15,[45,1229,1165],{"class":73},[45,1231,1233,1235,1237],{"class":47,"line":1232},16,[45,1234,1170],{"class":69},[45,1236,242],{"class":73},[45,1238,1239],{"class":92},"\"\u002Fblog\u002Fgetting-started-wth-laravel.html\"\n",[45,1241,1243],{"class":47,"line":1242},17,[45,1244,315],{"class":73},[45,1246,1248],{"class":47,"line":1247},18,[45,1249,210],{"class":73},[10,1251,1252,1253,1261,1262,1267],{},"How does it function? VitePress uses a Vite plugin to ",[135,1254,1257,1258,1260],{"href":1255,"rel":1256},"https:\u002F\u002Fgithub.com\u002Fvuejs\u002Fvitepress\u002Fblob\u002Fmain\u002Fsrc\u002Fnode\u002Fplugins\u002FstaticDataPlugin.ts#L11",[139],"detect imports from a ",[27,1259,976],{}," 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 ",[135,1263,1266],{"href":1264,"rel":1265},"https:\u002F\u002Fvite.dev\u002Fguide\u002Fapi-plugin#virtual-modules-convention",[139],"virtual modules in Vite",", yet more tailored to VitePress' needs.",[19,1269,1271],{"id":1270},"article-sorting","Article sorting",[10,1273,1274,1275,1278],{},"Currently, articles appear sorted by name, mimicking file directory ordering. Prioritize sorting them by ",[14,1276,1277],{},"date",", showcasing the latest articles first.",[10,1280,1281],{},"Optimization is achievable at build time, obviating runtime computation during hydration.",[10,1283,679,1284,1286],{},[27,1285,884],{},", sort data by date with a custom transformer:",[36,1288,1290],{"className":888,"code":1289,"filename":884,"language":374,"meta":41,"style":41},"import type { ContentData } from 'vitepress'\nimport { createContentLoader } from 'vitepress'\n\ndeclare const data: ContentData[]\nexport { data }\n\nexport default createContentLoader('blog\u002F*.md', {\n  transform: (data) => {\n    return data.sort((a, b) => {\n      return (\n        new Date(b.frontmatter.date).getTime()\n          - new Date(a.frontmatter.date).getTime()\n      )\n    })\n  },\n})\n",[27,1291,1292,1304,1314,1318,1332,1338,1342,1357,1376,1403,1411,1427,1444,1449,1454,1458],{"__ignoreMap":41},[45,1293,1294,1296,1298,1300,1302],{"class":47,"line":48},[45,1295,381],{"class":55},[45,1297,898],{"class":55},[45,1299,901],{"class":73},[45,1301,387],{"class":55},[45,1303,390],{"class":92},[45,1305,1306,1308,1310,1312],{"class":47,"line":66},[45,1307,381],{"class":55},[45,1309,912],{"class":73},[45,1311,387],{"class":55},[45,1313,390],{"class":92},[45,1315,1316],{"class":47,"line":86},[45,1317,408],{"emptyLinePlaceholder":407},[45,1319,1320,1322,1324,1326,1328,1330],{"class":47,"line":105},[45,1321,925],{"class":55},[45,1323,928],{"class":55},[45,1325,931],{"class":69},[45,1327,283],{"class":55},[45,1329,936],{"class":59},[45,1331,939],{"class":73},[45,1333,1334,1336],{"class":47,"line":111},[45,1335,428],{"class":55},[45,1337,946],{"class":73},[45,1339,1340],{"class":47,"line":425},[45,1341,408],{"emptyLinePlaceholder":407},[45,1343,1344,1346,1348,1350,1352,1354],{"class":47,"line":436},[45,1345,428],{"class":55},[45,1347,431],{"class":55},[45,1349,959],{"class":59},[45,1351,962],{"class":73},[45,1353,965],{"class":92},[45,1355,1356],{"class":73},", {\n",[45,1358,1359,1362,1365,1368,1371,1374],{"class":47,"line":442},[45,1360,1361],{"class":59},"  transform",[45,1363,1364],{"class":73},": (",[45,1366,877],{"class":1367},"sP4rz",[45,1369,1370],{"class":73},") ",[45,1372,1373],{"class":55},"=>",[45,1375,83],{"class":73},[45,1377,1378,1381,1384,1387,1390,1392,1394,1397,1399,1401],{"class":47,"line":667},[45,1379,1380],{"class":55},"    return",[45,1382,1383],{"class":73}," data.",[45,1385,1386],{"class":59},"sort",[45,1388,1389],{"class":73},"((",[45,1391,135],{"class":1367},[45,1393,96],{"class":73},[45,1395,1396],{"class":1367},"b",[45,1398,1370],{"class":73},[45,1400,1373],{"class":55},[45,1402,83],{"class":73},[45,1404,1405,1408],{"class":47,"line":807},[45,1406,1407],{"class":55},"      return",[45,1409,1410],{"class":73}," (\n",[45,1412,1413,1416,1419,1422,1425],{"class":47,"line":816},[45,1414,1415],{"class":55},"        new",[45,1417,1418],{"class":59}," Date",[45,1420,1421],{"class":73},"(b.frontmatter.date).",[45,1423,1424],{"class":59},"getTime",[45,1426,729],{"class":73},[45,1428,1429,1432,1435,1437,1440,1442],{"class":47,"line":1193},[45,1430,1431],{"class":55},"          -",[45,1433,1434],{"class":55}," new",[45,1436,1418],{"class":59},[45,1438,1439],{"class":73},"(a.frontmatter.date).",[45,1441,1424],{"class":59},[45,1443,729],{"class":73},[45,1445,1446],{"class":47,"line":1205},[45,1447,1448],{"class":73},"      )\n",[45,1450,1451],{"class":47,"line":1217},[45,1452,1453],{"class":73},"    })\n",[45,1455,1456],{"class":47,"line":1227},[45,1457,1180],{"class":73},[45,1459,1460],{"class":47,"line":1232},[45,1461,1462],{"class":73},"})\n",[10,1464,1465],{},"The data now appears sorted by date, with the most recent article leading.",[119,1467,1468],{"color":121,"icon":122},[10,1469,1470],{},"VitePress caches data output. To witness updates, restart the development server.",[19,1472,1474],{"id":1473},"displaying-the-articles","Displaying the articles",[10,1476,1477],{},"With articles ready for loading and sorting, our focus shifts to styling! 🎨",[10,1479,1480,1481,1484,1485,283],{},"Begin by creating a ",[27,1482,1483],{},"BlogCard.vue"," component in ",[27,1486,1487],{},".vitepress\u002Ftheme\u002Fcomponents",[36,1489,1491],{"className":577,"code":1490,"filename":1483,"language":579,"meta":41,"style":41},"\u003Cscript lang=\"ts\" setup>\nimport { ContentData } from 'vitepress'\n\ndefineProps\u003C{\n  post: ContentData\n}>()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Carticle\n    class=\"group relative border-4 border-black bg-white p-12 shadow-[8px_8px_0_black] transition duration-150 ease-linear space-y-6 hover:shadow-[12px_12px_0_black] hover:-translate-x-1 hover:-translate-y-1\"\n  >\n    \u003Ch2 class=\"text-4xl text-black font-medium\">\n      \u003Ca :href=\"post.url\">\n        {{ post.frontmatter.title }}\n        \u003Cspan class=\"absolute inset-0\" \u002F>\n      \u003C\u002Fa>\n    \u003C\u002Fh2>\n\n    \u003Cp class=\"text-xl text-black\">\n      {{ post.frontmatter.description }}\n    \u003C\u002Fp>\n  \u003C\u002Farticle>\n\u003C\u002Ftemplate>\n",[27,1492,1493,1509,1519,1523,1531,1541,1546,1554,1558,1566,1573,1583,1588,1604,1620,1625,1645,1654,1662,1667,1683,1689,1698,1708],{"__ignoreMap":41},[45,1494,1495,1497,1499,1501,1503,1505,1507],{"class":47,"line":48},[45,1496,586],{"class":73},[45,1498,589],{"class":505},[45,1500,592],{"class":59},[45,1502,595],{"class":73},[45,1504,598],{"class":92},[45,1506,601],{"class":59},[45,1508,604],{"class":73},[45,1510,1511,1513,1515,1517],{"class":47,"line":66},[45,1512,381],{"class":55},[45,1514,901],{"class":73},[45,1516,387],{"class":55},[45,1518,390],{"class":92},[45,1520,1521],{"class":47,"line":86},[45,1522,408],{"emptyLinePlaceholder":407},[45,1524,1525,1528],{"class":47,"line":105},[45,1526,1527],{"class":59},"defineProps",[45,1529,1530],{"class":73},"\u003C{\n",[45,1532,1533,1536,1538],{"class":47,"line":111},[45,1534,1535],{"class":1367},"  post",[45,1537,283],{"class":55},[45,1539,1540],{"class":59}," ContentData\n",[45,1542,1543],{"class":47,"line":425},[45,1544,1545],{"class":73},"}>()\n",[45,1547,1548,1550,1552],{"class":47,"line":436},[45,1549,613],{"class":73},[45,1551,589],{"class":505},[45,1553,604],{"class":73},[45,1555,1556],{"class":47,"line":442},[45,1557,408],{"emptyLinePlaceholder":407},[45,1559,1560,1562,1564],{"class":47,"line":667},[45,1561,586],{"class":73},[45,1563,628],{"class":505},[45,1565,604],{"class":73},[45,1567,1568,1570],{"class":47,"line":807},[45,1569,635],{"class":73},[45,1571,1572],{"class":505},"article\n",[45,1574,1575,1578,1580],{"class":47,"line":816},[45,1576,1577],{"class":59},"    class",[45,1579,595],{"class":73},[45,1581,1582],{"class":92},"\"group relative border-4 border-black bg-white p-12 shadow-[8px_8px_0_black] transition duration-150 ease-linear space-y-6 hover:shadow-[12px_12px_0_black] hover:-translate-x-1 hover:-translate-y-1\"\n",[45,1584,1585],{"class":47,"line":1193},[45,1586,1587],{"class":73},"  >\n",[45,1589,1590,1592,1594,1597,1599,1602],{"class":47,"line":1205},[45,1591,645],{"class":73},[45,1593,19],{"class":505},[45,1595,1596],{"class":59}," class",[45,1598,595],{"class":73},[45,1600,1601],{"class":92},"\"text-4xl text-black font-medium\"",[45,1603,604],{"class":73},[45,1605,1606,1608,1610,1613,1615,1618],{"class":47,"line":1217},[45,1607,772],{"class":73},[45,1609,135],{"class":505},[45,1611,1612],{"class":59}," :href",[45,1614,595],{"class":73},[45,1616,1617],{"class":92},"\"post.url\"",[45,1619,604],{"class":73},[45,1621,1622],{"class":47,"line":1227},[45,1623,1624],{"class":73},"        {{ post.frontmatter.title }}\n",[45,1626,1627,1630,1632,1634,1636,1639,1643],{"class":47,"line":1232},[45,1628,1629],{"class":73},"        \u003C",[45,1631,45],{"class":505},[45,1633,1596],{"class":59},[45,1635,595],{"class":73},[45,1637,1638],{"class":92},"\"absolute inset-0\"",[45,1640,1642],{"class":1641},"sPrNH"," \u002F",[45,1644,604],{"class":73},[45,1646,1647,1650,1652],{"class":47,"line":1242},[45,1648,1649],{"class":73},"      \u003C\u002F",[45,1651,135],{"class":505},[45,1653,604],{"class":73},[45,1655,1656,1658,1660],{"class":47,"line":1247},[45,1657,800],{"class":73},[45,1659,19],{"class":505},[45,1661,604],{"class":73},[45,1663,1665],{"class":47,"line":1664},19,[45,1666,408],{"emptyLinePlaceholder":407},[45,1668,1670,1672,1674,1676,1678,1681],{"class":47,"line":1669},20,[45,1671,645],{"class":73},[45,1673,10],{"class":505},[45,1675,1596],{"class":59},[45,1677,595],{"class":73},[45,1679,1680],{"class":92},"\"text-xl text-black\"",[45,1682,604],{"class":73},[45,1684,1686],{"class":47,"line":1685},21,[45,1687,1688],{"class":73},"      {{ post.frontmatter.description }}\n",[45,1690,1692,1694,1696],{"class":47,"line":1691},22,[45,1693,800],{"class":73},[45,1695,10],{"class":505},[45,1697,604],{"class":73},[45,1699,1701,1703,1706],{"class":47,"line":1700},23,[45,1702,660],{"class":73},[45,1704,1705],{"class":505},"article",[45,1707,604],{"class":73},[45,1709,1711,1713,1715],{"class":47,"line":1710},24,[45,1712,613],{"class":73},[45,1714,628],{"class":505},[45,1716,604],{"class":73},[10,1718,1719,1720,1722],{},"Enhance the ",[27,1721,999],{}," component to display articles with a loop:",[36,1724,1726],{"className":577,"code":1725,"filename":999,"language":579,"meta":41,"style":41},"\u003Cscript lang=\"ts\" setup>\nimport { data } from '..\u002F..\u002F..\u002Fdata\u002Fblog.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 class=\"space-y-10\">\n      \u003CBlogCard v-for=\"post in data\" :key=\"post.url\" :post=\"post\" \u002F>\n    \u003C\u002Fdiv>\n\n    \u003Cdiv class=\"flex justify-center\">\n      \u003Ca\n        href=\"\u002F\"\n        class=\"border-4 border-black bg-[#FFEB00] px-8 py-4 shadow-[4px_4px_0_black] transition duration-150 ease-linear hover:bg-[#fff90d] hover:shadow-[6px_6px_0_black] hover:-translate-x-[0.125rem] hover:-translate-y-[0.125rem]\"\n      >Back to Home\u003C\u002Fa>\n    \u003C\u002Fdiv>\n  \u003C\u002Fsection>\n\u003C\u002Ftemplate>\n",[27,1727,1728,1744,1754,1758,1774,1782,1786,1794,1809,1824,1829,1837,1841,1856,1910,1918,1922,1937,1944,1954,1964,1973,1981,1989],{"__ignoreMap":41},[45,1729,1730,1732,1734,1736,1738,1740,1742],{"class":47,"line":48},[45,1731,586],{"class":73},[45,1733,589],{"class":505},[45,1735,592],{"class":59},[45,1737,595],{"class":73},[45,1739,598],{"class":92},[45,1741,601],{"class":59},[45,1743,604],{"class":73},[45,1745,1746,1748,1750,1752],{"class":47,"line":66},[45,1747,381],{"class":55},[45,1749,1028],{"class":73},[45,1751,387],{"class":55},[45,1753,1033],{"class":92},[45,1755,1756],{"class":47,"line":86},[45,1757,408],{"emptyLinePlaceholder":407},[45,1759,1760,1762,1764,1766,1768,1770,1772],{"class":47,"line":105},[45,1761,712],{"class":55},[45,1763,715],{"class":73},[45,1765,718],{"class":69},[45,1767,721],{"class":73},[45,1769,595],{"class":55},[45,1771,726],{"class":59},[45,1773,729],{"class":73},[45,1775,1776,1778,1780],{"class":47,"line":111},[45,1777,613],{"class":73},[45,1779,589],{"class":505},[45,1781,604],{"class":73},[45,1783,1784],{"class":47,"line":425},[45,1785,408],{"emptyLinePlaceholder":407},[45,1787,1788,1790,1792],{"class":47,"line":436},[45,1789,586],{"class":73},[45,1791,628],{"class":505},[45,1793,604],{"class":73},[45,1795,1796,1798,1800,1802,1804,1807],{"class":47,"line":442},[45,1797,635],{"class":73},[45,1799,638],{"class":505},[45,1801,1596],{"class":59},[45,1803,595],{"class":73},[45,1805,1806],{"class":92},"\"space-y-16\"",[45,1808,604],{"class":73},[45,1810,1811,1813,1815,1817,1819,1822],{"class":47,"line":667},[45,1812,645],{"class":73},[45,1814,648],{"class":505},[45,1816,1596],{"class":59},[45,1818,595],{"class":73},[45,1820,1821],{"class":92},"\"text-6xl font-semibold\"",[45,1823,604],{"class":73},[45,1825,1826],{"class":47,"line":807},[45,1827,1828],{"class":73},"      {{ frontmatter.title }}\n",[45,1830,1831,1833,1835],{"class":47,"line":816},[45,1832,800],{"class":73},[45,1834,648],{"class":505},[45,1836,604],{"class":73},[45,1838,1839],{"class":47,"line":1193},[45,1840,408],{"emptyLinePlaceholder":407},[45,1842,1843,1845,1847,1849,1851,1854],{"class":47,"line":1205},[45,1844,645],{"class":73},[45,1846,756],{"class":505},[45,1848,1596],{"class":59},[45,1850,595],{"class":73},[45,1852,1853],{"class":92},"\"space-y-10\"",[45,1855,604],{"class":73},[45,1857,1858,1860,1863,1866,1868,1870,1873,1876,1878,1880,1883,1886,1888,1890,1893,1895,1897,1900,1902,1904,1906,1908],{"class":47,"line":1217},[45,1859,772],{"class":73},[45,1861,1862],{"class":505},"BlogCard",[45,1864,1865],{"class":55}," v-for",[45,1867,595],{"class":73},[45,1869,783],{"class":92},[45,1871,1872],{"class":73},"post ",[45,1874,1875],{"class":55},"in",[45,1877,931],{"class":73},[45,1879,783],{"class":92},[45,1881,1882],{"class":73}," :",[45,1884,1885],{"class":59},"key",[45,1887,595],{"class":73},[45,1889,783],{"class":92},[45,1891,1892],{"class":73},"post.url",[45,1894,783],{"class":92},[45,1896,1882],{"class":73},[45,1898,1899],{"class":59},"post",[45,1901,595],{"class":73},[45,1903,783],{"class":92},[45,1905,1899],{"class":73},[45,1907,783],{"class":92},[45,1909,795],{"class":73},[45,1911,1912,1914,1916],{"class":47,"line":1227},[45,1913,800],{"class":73},[45,1915,756],{"class":505},[45,1917,604],{"class":73},[45,1919,1920],{"class":47,"line":1232},[45,1921,408],{"emptyLinePlaceholder":407},[45,1923,1924,1926,1928,1930,1932,1935],{"class":47,"line":1242},[45,1925,645],{"class":73},[45,1927,756],{"class":505},[45,1929,1596],{"class":59},[45,1931,595],{"class":73},[45,1933,1934],{"class":92},"\"flex justify-center\"",[45,1936,604],{"class":73},[45,1938,1939,1941],{"class":47,"line":1247},[45,1940,772],{"class":73},[45,1942,1943],{"class":505},"a\n",[45,1945,1946,1949,1951],{"class":47,"line":1664},[45,1947,1948],{"class":59},"        href",[45,1950,595],{"class":73},[45,1952,1953],{"class":92},"\"\u002F\"\n",[45,1955,1956,1959,1961],{"class":47,"line":1669},[45,1957,1958],{"class":59},"        class",[45,1960,595],{"class":73},[45,1962,1963],{"class":92},"\"border-4 border-black bg-[#FFEB00] px-8 py-4 shadow-[4px_4px_0_black] transition duration-150 ease-linear hover:bg-[#fff90d] hover:shadow-[6px_6px_0_black] hover:-translate-x-[0.125rem] hover:-translate-y-[0.125rem]\"\n",[45,1965,1966,1969,1971],{"class":47,"line":1685},[45,1967,1968],{"class":73},"      >Back to Home\u003C\u002F",[45,1970,135],{"class":505},[45,1972,604],{"class":73},[45,1974,1975,1977,1979],{"class":47,"line":1691},[45,1976,800],{"class":73},[45,1978,756],{"class":505},[45,1980,604],{"class":73},[45,1982,1983,1985,1987],{"class":47,"line":1700},[45,1984,660],{"class":73},[45,1986,638],{"class":505},[45,1988,604],{"class":73},[45,1990,1991,1993,1995],{"class":47,"line":1710},[45,1992,613],{"class":73},[45,1994,628],{"class":505},[45,1996,604],{"class":73},[10,1998,1999,2000,2002],{},"Finally, update ",[27,2001,682],{}," with styles to enhance the blog's visual appeal:",[36,2004,2006],{"className":577,"code":2005,"filename":682,"language":579,"meta":41,"style":41},"\u003Cscript lang=\"ts\" setup>\nconst { frontmatter } = useData()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Cdiv class=\"min-h-screen bg-[#FC88FF] pt-16\">\n    \u003Cmain class=\"mx-auto max-w-screen-md\">\n      \u003CBlogIndex v-if=\"frontmatter.layout === 'blog'\" \u002F>\n    \u003C\u002Fmain>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n",[27,2007,2008,2024,2040,2048,2052,2060,2075,2090,2110,2118,2126],{"__ignoreMap":41},[45,2009,2010,2012,2014,2016,2018,2020,2022],{"class":47,"line":48},[45,2011,586],{"class":73},[45,2013,589],{"class":505},[45,2015,592],{"class":59},[45,2017,595],{"class":73},[45,2019,598],{"class":92},[45,2021,601],{"class":59},[45,2023,604],{"class":73},[45,2025,2026,2028,2030,2032,2034,2036,2038],{"class":47,"line":66},[45,2027,712],{"class":55},[45,2029,715],{"class":73},[45,2031,718],{"class":69},[45,2033,721],{"class":73},[45,2035,595],{"class":55},[45,2037,726],{"class":59},[45,2039,729],{"class":73},[45,2041,2042,2044,2046],{"class":47,"line":86},[45,2043,613],{"class":73},[45,2045,589],{"class":505},[45,2047,604],{"class":73},[45,2049,2050],{"class":47,"line":105},[45,2051,408],{"emptyLinePlaceholder":407},[45,2053,2054,2056,2058],{"class":47,"line":111},[45,2055,586],{"class":73},[45,2057,628],{"class":505},[45,2059,604],{"class":73},[45,2061,2062,2064,2066,2068,2070,2073],{"class":47,"line":425},[45,2063,635],{"class":73},[45,2065,756],{"class":505},[45,2067,1596],{"class":59},[45,2069,595],{"class":73},[45,2071,2072],{"class":92},"\"min-h-screen bg-[#FC88FF] pt-16\"",[45,2074,604],{"class":73},[45,2076,2077,2079,2081,2083,2085,2088],{"class":47,"line":436},[45,2078,645],{"class":73},[45,2080,765],{"class":505},[45,2082,1596],{"class":59},[45,2084,595],{"class":73},[45,2086,2087],{"class":92},"\"mx-auto max-w-screen-md\"",[45,2089,604],{"class":73},[45,2091,2092,2094,2096,2098,2100,2102,2104,2106,2108],{"class":47,"line":442},[45,2093,772],{"class":73},[45,2095,775],{"class":505},[45,2097,778],{"class":55},[45,2099,595],{"class":73},[45,2101,783],{"class":92},[45,2103,786],{"class":73},[45,2105,789],{"class":55},[45,2107,792],{"class":92},[45,2109,795],{"class":73},[45,2111,2112,2114,2116],{"class":47,"line":667},[45,2113,800],{"class":73},[45,2115,765],{"class":505},[45,2117,604],{"class":73},[45,2119,2120,2122,2124],{"class":47,"line":807},[45,2121,660],{"class":73},[45,2123,756],{"class":505},[45,2125,604],{"class":73},[45,2127,2128,2130,2132],{"class":47,"line":816},[45,2129,613],{"class":73},[45,2131,628],{"class":505},[45,2133,604],{"class":73},[19,2135,2137],{"id":2136},"conclusion","Conclusion",[2139,2140,2141,2146],"figure",{},[2142,2143],"img",{"alt":2144,"src":2145},"Blog Articles","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fimplementing-blog-index-with-vitepress-and-tailwind-css\u002Fvitepress-listing-articles.png",[2147,2148,2144],"figcaption",{},[10,2150,2151,2153,2154,2157],{},[14,2152,472],{}," simplifies the creation of index pages! The ",[14,2155,2156],{},"data loader"," enables article loading and sorting with minimal code, eliminating runtime overhead. This powerful feature allows us to focus on developing content and designing our blog.",[2159,2160,2161],"style",{},"html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .s8jYJ, html code.shiki .s8jYJ{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .snPdu, html code.shiki .snPdu{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sxrX7, html code.shiki .sxrX7{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#E1E4E8}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 .sovSZ, html code.shiki .sovSZ{--shiki-light:#22863A;--shiki-default:#22863A;--shiki-dark:#85E89D}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":41,"searchDepth":66,"depth":66,"links":2163},[2164,2168,2169,2170,2171,2172,2173],{"id":21,"depth":66,"text":22,"children":2165},[2166,2167],{"id":129,"depth":86,"text":130},{"id":322,"depth":86,"text":323},{"id":465,"depth":66,"text":466},{"id":562,"depth":66,"text":563},{"id":844,"depth":66,"text":845},{"id":1270,"depth":66,"text":1271},{"id":1473,"depth":66,"text":1474},{"id":2136,"depth":66,"text":2137},"4d93a3c5-f3ff-4ff6-a569-5234ef805850","2024-10-22","Learn to create a list of blog articles using VitePress, a crucial feature for any content-centric website. Utilize data loaders to load articles.",{"branch":2178},"04.comprehensive-guide-to-listing-blog-articles",null,{},"\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fimplementing-blog-index-with-vitepress-and-tailwind-css","---\ncontentId: 4d93a3c5-f3ff-4ff6-a569-5234ef805850\npart: 4\ntitle: Implementing Blog Index with VitePress and Tailwind CSS\ndescription: Learn to create a list of blog articles using VitePress, a crucial feature for any content-centric website. Utilize data loaders to load articles.\ngithub:\n  branch: 04.comprehensive-guide-to-listing-blog-articles\ndate: 2024-10-22\nseriesSlug: create-a-blog-with-vitepress-and-vue-js-from-scratch\n---\n\nBefore diving into the core task, we must set up **Tailwind CSS**. This step, while straightforward, is essential for styling our blog effectively.\n\n## Tailwind CSS configuration\n\nWe need to direct Tailwind CSS to the location of our files. In the `tailwind.config.cjs` file at the project root, utilize the `content` key to specify which files to analyze to generate the necessary CSS classes.\n\n```js [tailwind.config.cjs]\n\u002F** @type {import('tailwindcss').Config} *\u002F\nmodule.exports = {\n  content: ['.\u002Fsrc\u002F**\u002F*.md', '.\u002F.vitepress\u002Ftheme\u002F**\u002F*.{vue,ts}'],\n  \u002F\u002F ...\n}\n```\n\nWe instruct Tailwind CSS to scan both Markdown files and all Vue and TypeScript files in the theme directory.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nMonitoring Markdown files is vital since HTML can exist within them, and components can also be included.\n::\n\n### Integrating Prettier with Tailwind CSS plugin\n\nAdditionally, we will configure [Prettier](https:\u002F\u002Fprettier.io\u002F) for code formatting and implement the Prettier Tailwind CSS **plugin** to automatically sort classes.\n\nTo install Prettier and the **plugin**, execute:\n\n```sh [terminal]\npnpm add -D prettier prettier-plugin-tailwindcss\n```\n\nCreate a `.prettierrc` file at the project's root with the following configuration:\n\n```json [Example]\n{\n  \"plugins\": [\"prettier-plugin-tailwindcss\"]\n}\n```\n\nIf you're using **Visual Studio Code**, include the following in `.vscode\u002Fsettings.json` to enable auto-formatting on save:\n\n```json [.vscode\u002Fsettings.json]\n{\n  \"prettier.enable\": true,\n  \"editor.formatOnSave\": true,\n  \"editor.defaultFormatter\": \"esbenp.prettier-vscode\"\n}\n```\n\nAdd a script in `package.json` to format files using **Prettier**:\n\n```json [package.json]\n{\n  \"scripts\": {\n    \"format\": \"prettier --write .\"\n  }\n}\n```\n\n### Connecting Tailwind CSS to the project\n\nFinally, we need to link our project with the CSS generated by Tailwind CSS. In `.vitepress\u002Ftheme\u002Fstyles`, create an `app.css` file and append the Tailwind CSS directives:\n\n```css [app.css]\n@tailwind base;\n@tailwind components;\n@tailwind utilities;\n```\n\nThen, import this file into `.vitepress\u002Ftheme\u002Findex.ts`:\n\n```ts [.vitepress\u002Ftheme\u002Findex.ts]\nimport { Theme } from 'vitepress'\nimport Layout from '.\u002FLayout.vue'\n\nimport '.\u002Fstyles\u002Fapp.css' \u002F\u002F [!code ++]\n\nexport default {\n  Layout,\n} satisfies Theme\n```\n\nImporting a CSS file directly within a TypeScript file poses no issues as [Vite seamlessly handles it](https:\u002F\u002Fvite.dev\u002Fguide\u002Ffeatures.html#css).\n\nNow, we're prepared to start styling our blog!\n\n## Developing the blog page\n\nWe require a page to display all our blog articles. As discussed in earlier articles, **VitePress** treats Markdown files in the `src` directory as pages. Thus, we'll create a `blog.md` file in the `src` directory. This page will map to the **\u002Fblog** route.\n\n```md [blog.md]\n---\nlayout: blog\ntitle: Blog\ndescription: The latest articles, tutorials, and resources on web development, programming, and more.\n---\n```\n\nThe body remains empty to allow the component to manage the page structure. This component will include:\n\n- A comprehensive list of articles\n- A navigation button to return to the homepage\n\n::callout{icon=\"i-ph-lightbulb-duotone\" color=\"success\"}\nDetermine content placement by considering theme-neutral content. For instance, is the article list part of the theme or the content? A theme may display this list in various formats, column, grid, or carousel, which the theme dictates. Content must remain theme-agnostic. _There is some exception to this rule, especially for inlined content._\n::\n\n## Routing the blog page to the component\n\nWithin `.vitepress\u002Ftheme\u002Fpages`, create the `Blog\u002FBlogIndex.vue` component:\n\n```vue [Blog\u002FBlogIndex.vue]\n\u003Cscript lang=\"ts\" setup>\n\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Csection>\n    \u003Ch1>Blog\u003C\u002Fh1>\n  \u003C\u002Fsection>\n\u003C\u002Ftemplate>\n```\n\nThis component structures the page. It employs the correlated Markdown file to present the title and articles.\n\nIn `Layout.vue`, link the layout to the component by extracting the `layout` key from the current file's frontmatter for appropriate component display.\n\n```vue [Layout.vue]\n\u003Cscript lang=\"ts\" setup>\nconst { frontmatter } = useData()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Cdiv>\n    \u003Cmain>\n      \u003CBlogIndex v-if=\"frontmatter.layout === 'blog'\" \u002F>\n    \u003C\u002Fmain>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n```\n\nNow, navigating to the **\u002Fblog** route displays the `BlogIndex` component as VitePress loads the `blog.md` file, exposing its frontmatter to `Layout.vue` through the `useData` function.\n\n## Loading all articles\n\nNow comes the exciting part! We'll load all articles from the **src\u002Fblog** directory. Employing [VitePress data loaders](https:\u002F\u002Fvitepress.dev\u002Fguide\u002Fdata-loading), this can be achieved with minimal code and no runtime burden. ✨\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nEnsure the presence of some Markdown files in the `src\u002Fblog` directory. You can copy them from the [GitHub repository](https:\u002F\u002Fgithub.com\u002Fbarbapapazes\u002Fgarabit\u002Ftree\u002Fmain\u002Fsrc\u002Fblog).\n::\n\nIn a `data` directory within `.vitepress`, create the `blog.data.ts` file:\n\n```ts [blog.data.ts]\nimport type { ContentData } from 'vitepress'\nimport { createContentLoader } from 'vitepress'\n\ndeclare const data: ContentData[]\nexport { data }\n\nexport default createContentLoader('blog\u002F*.md')\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nEnsure the extension `.data.ts` is used; it's crucial for functionality.\n::\n\nWhat's happening here? **VitePress** anticipates local **Markdown** file loading, providing a helper function for the task. Simply specify the directory.\n\nThe default type may be incorrect due to server transformation before data access. Export a custom type via the `data` variable for correct imports.\n\nLoad this module in the `BlogIndex.vue` component and render it to view the result:\n\n```vue [BlogIndex.vue]\n\u003Cscript lang=\"ts\" setup>\nimport { data } from '..\u002F..\u002F..\u002Fdata\u002Fblog.data'\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Csection>\n    \u003Ch1>Blog\u003C\u002Fh1>\n\n    {{ data }}\n  \u003C\u002Fsection>\n\u003C\u002Ftemplate>\n```\n\nData output is an array of objects, each representing a **Markdown** file. You can view each file's frontmatter and URL:\n\n```json [Example]\n[\n  {\n    \"frontmatter\": {\n      \"title\": \"Getting Started with Vue 3 and Vite\",\n      \"description\": \"Learn how to set up a new Vue 3 project with Vite, the fast build tool for modern web development. Explore the basics of Vue 3, including the Composition API, reactivity, components, and more.\",\n      \"date\": \"2024-09-14T00:00:00.000Z\"\n    },\n    \"url\": \"\u002Fblog\u002Fgetting-started-with-vue3-and-vite.html\"\n  },\n  {\n    \"frontmatter\": {\n      \"title\": \"Getting Started with Laravel\",\n      \"description\": \"Learn how to set up a new Laravel project and build a simple web application. Explore the basics of Laravel, including routing, views, controllers, and more.\",\n      \"date\": \"2024-10-14T00:00:00.000Z\"\n    },\n    \"url\": \"\u002Fblog\u002Fgetting-started-wth-laravel.html\"\n  }\n]\n```\n\nHow does it function? 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\n## Article sorting\n\nCurrently, articles appear sorted by name, mimicking file directory ordering. Prioritize sorting them by **date**, showcasing the latest articles first.\n\nOptimization is achievable at build time, obviating runtime computation during hydration.\n\nIn `blog.data.ts`, sort data by date with a custom transformer:\n\n```ts [blog.data.ts]\nimport type { ContentData } from 'vitepress'\nimport { createContentLoader } from 'vitepress'\n\ndeclare const data: ContentData[]\nexport { data }\n\nexport default createContentLoader('blog\u002F*.md', {\n  transform: (data) => {\n    return data.sort((a, b) => {\n      return (\n        new Date(b.frontmatter.date).getTime()\n          - new Date(a.frontmatter.date).getTime()\n      )\n    })\n  },\n})\n```\n\nThe data now appears sorted by date, with the most recent article leading.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nVitePress caches data output. To witness updates, restart the development server.\n::\n\n## Displaying the articles\n\nWith articles ready for loading and sorting, our focus shifts to styling! 🎨\n\nBegin by creating a `BlogCard.vue` component in `.vitepress\u002Ftheme\u002Fcomponents`:\n\n```vue [BlogCard.vue]\n\u003Cscript lang=\"ts\" setup>\nimport { ContentData } from 'vitepress'\n\ndefineProps\u003C{\n  post: ContentData\n}>()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Carticle\n    class=\"group relative border-4 border-black bg-white p-12 shadow-[8px_8px_0_black] transition duration-150 ease-linear space-y-6 hover:shadow-[12px_12px_0_black] hover:-translate-x-1 hover:-translate-y-1\"\n  >\n    \u003Ch2 class=\"text-4xl text-black font-medium\">\n      \u003Ca :href=\"post.url\">\n        {{ post.frontmatter.title }}\n        \u003Cspan class=\"absolute inset-0\" \u002F>\n      \u003C\u002Fa>\n    \u003C\u002Fh2>\n\n    \u003Cp class=\"text-xl text-black\">\n      {{ post.frontmatter.description }}\n    \u003C\u002Fp>\n  \u003C\u002Farticle>\n\u003C\u002Ftemplate>\n```\n\nEnhance the `BlogIndex.vue` component to display articles with a loop:\n\n```vue [BlogIndex.vue]\n\u003Cscript lang=\"ts\" setup>\nimport { data } from '..\u002F..\u002F..\u002Fdata\u002Fblog.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 class=\"space-y-10\">\n      \u003CBlogCard v-for=\"post in data\" :key=\"post.url\" :post=\"post\" \u002F>\n    \u003C\u002Fdiv>\n\n    \u003Cdiv class=\"flex justify-center\">\n      \u003Ca\n        href=\"\u002F\"\n        class=\"border-4 border-black bg-[#FFEB00] px-8 py-4 shadow-[4px_4px_0_black] transition duration-150 ease-linear hover:bg-[#fff90d] hover:shadow-[6px_6px_0_black] hover:-translate-x-[0.125rem] hover:-translate-y-[0.125rem]\"\n      >Back to Home\u003C\u002Fa>\n    \u003C\u002Fdiv>\n  \u003C\u002Fsection>\n\u003C\u002Ftemplate>\n```\n\nFinally, update `Layout.vue` with styles to enhance the blog's visual appeal:\n\n```vue [Layout.vue]\n\u003Cscript lang=\"ts\" setup>\nconst { frontmatter } = useData()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Cdiv class=\"min-h-screen bg-[#FC88FF] pt-16\">\n    \u003Cmain class=\"mx-auto max-w-screen-md\">\n      \u003CBlogIndex v-if=\"frontmatter.layout === 'blog'\" \u002F>\n    \u003C\u002Fmain>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n```\n\n## Conclusion\n\n![Blog Articles](\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fimplementing-blog-index-with-vitepress-and-tailwind-css\u002Fvitepress-listing-articles.png)\n\n**VitePress** simplifies the creation of index pages! The **data loader** enables article loading and sorting with minimal code, eliminating runtime overhead. This powerful feature allows us to focus on developing content and designing our blog.\n",{"title":5,"description":2176},"create-a-blog-with-vitepress-and-vue-js-from-scratch",{"loc":2181,"images":2186},[2187],{"loc":2145},"series\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fimplementing-blog-index-with-vitepress-and-tailwind-css","mAkF0tTGzMYQeEXMym8HINnNG89AxbCYb0IAjmCyDqw",{"overview":2191,"chapters":2423},{"id":2192,"title":2193,"body":2194,"contentId":2403,"date":2404,"description":2405,"extension":493,"github":2406,"meetTheInstructor":2409,"meta":2410,"navigation":407,"part":2179,"path":2411,"rawbody":2412,"robots":2179,"schemaOrg":2179,"seo":2413,"seriesSlug":2184,"sitemap":2414,"stem":2417,"subtitle":2418,"topics":2419,"__hash__":2422},"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":2195,"toc":2400},[2196,2199,2213,2227,2359,2369,2377,2384,2387,2390,2394],[10,2197,2198],{},"Hello and welcome! 👋",[10,2200,2201,2202,2205,2206,2208,2209,2212],{},"You're about to embark on the \"Create a ",[14,2203,2204],{},"Blog"," with ",[14,2207,472],{}," and ",[14,2210,2211],{},"Vue.js"," from Scratch\" series!",[10,2214,2215,2216,2222,2223,2226],{},"Throughout this journey, we will construct a practical blog from the ground up using ",[135,2217,2220],{"href":2218,"rel":2219},"https:\u002F\u002Fvitepress.dev\u002F",[139],[14,2221,472],{},". We will explore a range of topics from initial configuration to deploying on ",[14,2224,2225],{},"Cloudflare Pages",", including:",[540,2228,2229,2253,2262,2268,2279,2285,2295,2305,2315,2327,2344,2350],{},[543,2230,2231,2234,2235,2238,2239,2208,2245,2252],{},[14,2232,2233],{},"Getting Started with VitePress: Project Setup and Essentials",": Learn to set up a fresh ",[14,2236,2237],{},"VitePress project"," by incorporating ",[135,2240,2243],{"href":2241,"rel":2242},"https:\u002F\u002Ftailwindcss.com\u002F",[139],[14,2244,16],{},[135,2246,2249],{"href":2247,"rel":2248},"https:\u002F\u002Fgithub.com\u002Funplugin\u002Funplugin-vue-components",[139],[14,2250,2251],{},"unplugin-vue-components"," for an enhanced development process.",[543,2254,2255,2258,2259],{},[14,2256,2257],{},"From Default to Custom: Building a VitePress Blog Theme",": We will entirely remove the default theme and create a personalized theme. ",[557,2260,2261],{},"You'll be surprised by its simplicity!",[543,2263,2264,2267],{},[14,2265,2266],{},"Optimize Your VitePress Blog's Architecture Design",": Discover how to organize code and design your blog for scalability and maintainability.",[543,2269,2270,2272,2273,74],{},[14,2271,5],{},": Create a list of blog posts. This will introduce ",[135,2274,2276],{"href":855,"rel":2275},[139],[14,2277,2278],{},"data loaders from VitePress",[543,2280,2281,2284],{},[14,2282,2283],{},"Single Blog Rendering in VitePress with Tailwind Typography",": Create a page dedicated to reading each blog post.",[543,2286,2287,2290,2291,2294],{},[14,2288,2289],{},"Deploy VitePress Blog Globally with Cloudflare Pages",": Integrate ",[14,2292,2293],{},"SEO metadata"," for improved search engine visibility, eliminating the need for manual updates.",[543,2296,2297,2300,2301,2304],{},[14,2298,2299],{},"Showcase Your GitHub Projects on Your VitePress Blog",": Develop a page to display your ",[14,2302,2303],{},"GitHub"," endeavors, extending the use of data loaders and demonstrating their flexibility.",[543,2306,2307,2310,2311,2314],{},[14,2308,2309],{},"Creating Open Graph Images Automatically for Each Blog Post",": Efficiently create ",[14,2312,2313],{},"Open Graph images"," for each post, saving time and enhancing appeal.",[543,2316,2317,2319,2320,2326],{},[14,2318,2289],{},": Seamlessly deploy your blog to ",[135,2321,2324],{"href":2322,"rel":2323},"https:\u002F\u002Fpages.cloudflare.com\u002F",[139],[14,2325,2225],{},", achieving this in just a few clicks!",[543,2328,2329,2332,2333,2205,2336,2343],{},[14,2330,2331],{},"Ensure Blog Quality with Playwright Automated Testing",": Implement ",[14,2334,2335],{},"end-to-end testing",[135,2337,2340],{"href":2338,"rel":2339},"https:\u002F\u002Fplaywright.dev\u002F",[139],[14,2341,2342],{},"Playwright"," to ensure your blog functions as expected.",[543,2345,2346,2349],{},[14,2347,2348],{},"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.",[543,2351,2352,2355,2356,2358],{},[14,2353,2354],{},"Migrating Our VitePress Blog to Tailwind CSS Version 4",": Upgrade our blog to the latest version of ",[14,2357,16],{}," to leverage its new features and improvements.",[10,2360,2361,2362,2365,2366,2368],{},"By the conclusion, you will possess a fully operational and captivating ",[14,2363,2364],{},"blog",", allowing you to concentrate exclusively on producing ",[14,2367,33],{},", which is paramount. Simply write and publish, as the blog will autonomously manage the rest.",[2139,2370,2371,2375],{},[2142,2372],{"alt":2373,"src":2374},"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",[2147,2376,2373],{},[10,2378,2379,2380,2383],{},"This series offers a detailed, step-by-step ",[14,2381,2382],{},"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,2385,2386],{},"Should you have any inquiries, please feel free to engage in the comments section under each article.",[10,2388,2389],{},"I hope you find this series truly enjoyable! 🚀",[19,2391,2393],{"id":2392},"chapters","Chapters",[2395,2396],"series-chapters-list",{"className":2397},[2398,2399],"mx-auto","max-w-5xl",{"title":41,"searchDepth":66,"depth":66,"links":2401},[2402],{"id":2392,"depth":66,"text":2393},"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":2407,"repository":2408},"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":2193,"description":2405},{"loc":2411,"images":2415},[2416],{"loc":2374},"series\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch","A new perspective on blogging with VitePress and Vue.js",[2420,2421,2364],"vuejs","vitepress","H9cubHgLKM0Siblzkwf7mDsFVYr2CLbh_ciFOpQrSVk",[2424,2430,2436,2442,2444,2450,2457,2463,2469,2475,2481,2488],{"contentId":2425,"title":2233,"description":2426,"path":2427,"part":48,"github":2428,"topics":2179},"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":2429},"01.project-initialization",{"contentId":2431,"title":2257,"description":2432,"path":2433,"part":66,"github":2434,"topics":2179},"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":2435},"02.the-basics-for-a-custom-theme",{"contentId":2437,"title":2266,"description":2438,"path":2439,"part":86,"github":2440,"topics":2179},"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":2441},"03.define-the-design-of-the-blog-architecture",{"contentId":2174,"title":5,"description":2176,"path":2181,"part":105,"github":2443,"topics":2179},{"branch":2178},{"contentId":2445,"title":2283,"description":2446,"path":2447,"part":111,"github":2448,"topics":2179},"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":2449},"05.read-a-single-blog-article",{"contentId":2451,"title":2452,"description":2453,"path":2454,"part":425,"github":2455,"topics":2179},"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":2456},"06.seo-metadata-and-sitemap",{"contentId":2458,"title":2299,"description":2459,"path":2460,"part":436,"github":2461,"topics":2179},"a4a933b8-07a5-4587-ad54-c3f9e30cbf45","Enhance your VitePress blog with GitHub projects. Learn API data retrieval and how to display your projects on your blog.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fshowcase-your-github-projects-on-your-vitepress-blog",{"branch":2462},"07.showcase-your-github-projects",{"contentId":2464,"title":2309,"description":2465,"path":2466,"part":442,"github":2467,"topics":2179},"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":2468},"08.automatically-generated-open-graph-images",{"contentId":2470,"title":2289,"description":2471,"path":2472,"part":667,"github":2473,"topics":2179},"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":2474},"09.share-the-blog-globally",{"contentId":2476,"title":2331,"description":2477,"path":2478,"part":807,"github":2479,"topics":2179},"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":2480},"10.automate-testing",{"contentId":2482,"title":2483,"description":2484,"path":2485,"part":816,"github":2486,"topics":2179},"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":2487},"11.internal-refactor",{"contentId":2489,"title":2354,"description":2490,"path":2491,"part":1193,"github":2492,"topics":2179},"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":2493},"12.migration-to-tailwind-css-4",1795016692172]