国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

從零用VitePress搭建博客教程(5) - 如何自定義頁面模板、給頁面添加獨有的className和使頁面標(biāo)題變成側(cè)邊目錄?

這篇具有很好參考價值的文章主要介紹了從零用VitePress搭建博客教程(5) - 如何自定義頁面模板、給頁面添加獨有的className和使頁面標(biāo)題變成側(cè)邊目錄?。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

接上一節(jié):從零用VitePress搭建博客教程(4) – 如何自定義首頁布局和主題樣式修改?

上一節(jié)其實我們也簡單說了自定義頁面模板,這一節(jié)更加詳細一點說明,開始之前我們要知道在vitePress中,.md的文件是可以直接編寫vue的代碼的。

比如我們現(xiàn)在來自定義一個前端網(wǎng)址導(dǎo)航頁面

八、自定義一些頁面模板

1、編寫組件代碼

想自定義頁面模板樣式,該如何做呢?
我們先在theme/components下新建siteList.vue文件,編寫模板,代碼如下:

<template>
  <!-- 網(wǎng)址分類模塊 -->
  <section class="site-section">
     <!-- 標(biāo)題 -->
    <h2 class="title">{{ props.title }}</h2>
    <!-- 網(wǎng)址列表 -->
    <ul class="list">
      <li class="item" v-for="(v, index) in props.data" :key="v.name">
        <a class="link" :href="v.link" target="_blank">
          <span class="num">{{ index + 1 }}</span>
          <h4 class="name">{{ v.name }}</h4>
          <p class="desc">{{ v.desc }}</p>
        </a>
      </li>
    </ul>
  </section>
</template>
<script setup>
const props = defineProps({
  title: String,
  data: {
    type: Array,
    default: [],
  },
});
 
</script>
<style lang="scss" scoped>
/*單行文本省略號*/
@mixin single-ellipsis {
  overflow: hidden;
  word-wrap: normal;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.site-section {
  .title {
    color: #222;
  }
  .list {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    padding-left: 0;
    .item {
      width: 212px;
      margin: 15px 15px 0 0px;
      background: #fff;
      position: relative;
      .link {
        width: 210px;
        display: block;
        border: 1px solid #e3e3e3;
        padding-bottom: 8px;
        border-radius: 6px;
        .num {
          display: block;
          width: 24px;
          height: 18px;
          line-height: 18px;
          position: absolute;
          color: #666;
          font-size: 14px;
          text-align: center;
          right: 5px;
          top: 5px;
        }
        .name {
          width: 80%;
          height: 26px;
          padding-left: 10px;
          font-size: 16px;
          font-weight: 600;
          color: #06a4fa;
          margin-top: 15px;
          @include single-ellipsis;
        }
        .desc {
          font-size: 12px;
          margin: 10px 10px 0;
          color: #b1b1b1;
          height: 36px;
          line-height: 18px;
          @include single-ellipsis;
        }
        &:hover {
          text-decoration: none;
          border: 1px solid var(--vp-c-brand);
          filter: brightness(1.15);
          box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
          transform: rotateY(-0.1deg) scale(1.001) translateZ(0);
          transition: all 0.24s ease;
          .name {
            color: var(--vp-c-brand);
          }
          .num {
            background: var(--vp-c-brand);
            color: #fff;
          }
        }
      }
    }
  }
}
</style>

?文章來源地址http://www.zghlxwxcb.cn/news/detail-710956.html

2、注冊組件

上面我們寫好組件代碼后,需注冊為全局組件,如下theme/index.js的配置,把SiteList注冊為全局組件,然后在頁面引用即可。

// https://vitepress.dev/guide/custom-theme
import { h } from "vue";
import siteList from "./components/siteList.vue";
 
import DefaultTheme from "vitepress/theme";
import "./styles/custom.scss";
import "./styles/site.scss";
import "./styles/rainbow.css";
 
export default {
  ...DefaultTheme,
  NotFound: () => "404", // <- this is a Vue 3 functional component
  enhanceApp({ app, router, siteData }) {
    // app is the Vue 3 app instance from createApp()
    // router is VitePress' custom router (see `lib/app/router.js`)
    // siteData is a ref of current site-level metadata.
    app.component("SiteList", siteList);
  },
};

?

3、如何給頁面添加自定義類className

官方就有最簡單的配置方法,向特定頁面添加額外的類名pageClass:比如給page.md頁面配置,只需如下即可

---
pageClass: site-layout
---

  然后在下面寫樣式即可

.site-layout {
  ...
}

  當(dāng)然還有一種方法是:我們還可以在theme/index.js,通過js添加(Layout配置),這個一個頁面可以添加多個className了。

// https://vitepress.dev/guide/custom-theme
import { useData } from "vitepress";
import siteList from "./components/siteList.vue";
 
import DefaultTheme from "vitepress/theme";
import "./styles/custom.scss";
import "./styles/site.scss";
import "./styles/rainbow.css";
 
export default {
  ...DefaultTheme,
  NotFound: () => "404", // <- this is a Vue 3 functional component
  enhanceApp({ app, router, siteData }) {
    // app is the Vue 3 app instance from createApp()
    // router is VitePress' custom router (see `lib/app/router.js`)
    // siteData is a ref of current site-level metadata.
    // 注冊全局組件
    app.component("SiteList", siteList);
  },
  // 自定義布局配置
  Layout: () => {
    const props = {};
    // 獲取 frontmatter
    const { frontmatter } = useData();
 
    /* 添加自定義 class */
    if (frontmatter.value?.layoutClass) {
      props.class = frontmatter.value.layoutClass;
    }
  },
};

?

  然后同樣的page.md頁面,我們可以通過layoutClass設(shè)置另一個className了,如下

---
layoutClass: site-page
pageClass: site-layout
---

  

4、頁面使用組件

同樣還是上面的page.md,我們使用組件如下

---
pageClass: site-layout
---
 
<SiteList v-for="model in siteData" :key="model.title" :title="model.title" :data="model.items" />
<script setup>
// 網(wǎng)址導(dǎo)航頁面的數(shù)據(jù)
import siteData from "./data/page.js";
</script>

?

效果

從零用VitePress搭建博客教程(5) - 如何自定義頁面模板、給頁面添加獨有的className和使頁面標(biāo)題變成側(cè)邊目錄?

?

?

5、如何使頁面標(biāo)題變成側(cè)邊目錄呢?

從上面圖中可以看出,我們發(fā)現(xiàn)右邊沒有側(cè)邊導(dǎo)航,那么如何使頁面標(biāo)題變成側(cè)邊目錄呢?

這個時候需要用到@mdit-vue/shared,siteList.vue組件修改代碼如下

<template>
  <!-- 網(wǎng)址分類模塊 -->
  <!-- <backTop></backTop> -->
  <section class="site-section">
    <!-- 瞄點標(biāo)題 -->
    <h2 class="title" :id="createTitle">
      {{ props.title }}
      <a class="anchor" :href="`#${createTitle}`" aria-hidden="true"></a>
    </h2>
    <!-- 網(wǎng)址列表 -->
    <ul class="list">
      <li class="item" v-for="(v, index) in props.data" :key="v.name">
        <a class="link" :href="v.link" target="_blank">
          <span class="num">{{ index + 1 }}</span>
          <h4 class="name">{{ v.name }}</h4>
          <p class="desc">{{ v.desc }}</p>
        </a>
      </li>
    </ul>
  </section>
</template>
<script setup>
import { computed } from "vue";
import { slugify } from "@mdit-vue/shared";
const props = defineProps({
  title: String,
  data: {
    type: Array,
    default: [],
  },
});
 
// 生成側(cè)邊欄markdown的目錄
const createTitle = computed(() => {
  return slugify(props.title);
});
</script>

發(fā)現(xiàn)目錄已經(jīng)有了,效果如下:  

從零用VitePress搭建博客教程(5) - 如何自定義頁面模板、給頁面添加獨有的className和使頁面標(biāo)題變成側(cè)邊目錄?

?

這個時候目錄是在頁面右邊的,那么如何變成在左側(cè)邊欄呢?我們通過樣式調(diào)整即可,site.scss

/**
  網(wǎng)址導(dǎo)航頁面樣式
**/
 
.site-layout {
  /*布局調(diào)整*/
  .VPDoc {
    .container {
      max-width: 100% !important;
      justify-content: flex-start !important;
      .aside {
        order: 1;
      }
      .content {
        order: 2;
        max-width: 100% !important;
        .content-container {
          max-width: 100% !important;
        }
      }
      .main {
        height: auto;
        overflow: hidden;
        .vp-doc h2 {
          margin: 0;
        }
      }
    }
  }
  /* 隱藏底部的在 github 上編輯此頁模塊*/
  .VPDocFooter {
    display: none;
  }
}

  從零用VitePress搭建博客教程(5) - 如何自定義頁面模板、給頁面添加獨有的className和使頁面標(biāo)題變成側(cè)邊目錄?

6、如何自定義頁面的底部?

我們新建一個siteFooter.vue組件,然后在theme/index.js通過h函數(shù)配置即可,這里使用到doc-after插槽,

默認(rèn)主題布局中可用插槽的完整列表:https://process1024.github.io/vitepress/guide/theme-introduction

<template>
  <div class="site-footer">
    網(wǎng)址導(dǎo)航自定義底部信息
  </div>
</template>
mport { h } from "vue";
import siteFooter from "./components/siteFooter.vue";
 
import DefaultTheme from "vitepress/theme";
 
export default {
  ...DefaultTheme,
  NotFound: () => "404", // <- this is a Vue 3 functional component
  enhanceApp({ app, router, siteData }) {
    // app is the Vue 3 app instance from createApp()
    // router is VitePress' custom router (see `lib/app/router.js`)
    // siteData is a ref of current site-level metadata.
    // 注冊全局組件
  },
  // 自定義布局配置
  Layout: () => {
    return h(DefaultTheme.Layout, props, {
      // 自定義文檔底部,使用doc-after插槽
      "doc-after": () => h(siteFooter),
    });
  },
};

從零用VitePress搭建博客教程(5) - 如何自定義頁面模板、給頁面添加獨有的className和使頁面標(biāo)題變成側(cè)邊目錄?

github項目地址:https://github.com/msyuan/vitePress-project

在線預(yù)覽效果:https://msyuan.github.io/vitePress-project

原文地址:http://www.qianduan8.com/2048.html

?

到了這里,關(guān)于從零用VitePress搭建博客教程(5) - 如何自定義頁面模板、給頁面添加獨有的className和使頁面標(biāo)題變成側(cè)邊目錄?的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 5分鐘使用VitePress + GithubAction搭建個人博客

    5分鐘使用VitePress + GithubAction搭建個人博客

    ?作者:TuNan ?個人主頁:圖南的個人主頁 ??歡迎關(guān)注??點贊??收藏?留言?? 先決條件 Node.js 版本 16 或更高版本。 用于通過命令行界面(CLI)訪問 VitePress 的終端。 具有 Markdown 語法支持的文本編輯器。推薦使用 VSCode) 以及官方 Vue 擴展。 VitePress 可以單獨使用,也可以安

    2024年02月04日
    瀏覽(57)
  • 10分鐘 使用VitePress和GitHub Actions快速搭建發(fā)布個人博客

    10分鐘 使用VitePress和GitHub Actions快速搭建發(fā)布個人博客

    VitePress官網(wǎng)Getting Started | VitePress VitePress 是一個靜態(tài)站點生成器 (SSG),旨在構(gòu)建快速、以內(nèi)容為中心的網(wǎng)站。 Node.js (nodejs.org)Node版本18或更高版本 **使用 node -v **查看node版本 創(chuàng)建文件夾并進入到項目的目錄 初始化項目 這里會帶有設(shè)置向?qū)?安裝項目所需的 vitepress 依賴 在

    2024年02月03日
    瀏覽(19)
  • 百度小程序開發(fā)平臺源碼系統(tǒng):海量模板,定義移動時代的最佳體驗 附帶完整的搭建教程

    百度小程序開發(fā)平臺源碼系統(tǒng):海量模板,定義移動時代的最佳體驗 附帶完整的搭建教程

    移動互聯(lián)網(wǎng)的飛速發(fā)展,小程序成為了眾多企業(yè)和開發(fā)者的新寵。今天來給大家分享一個百度小程序的開發(fā)平臺,帶完整的搭建教程。 以下是部分代碼示例: 系統(tǒng)特色功能一覽: ? ? 1.海量模板,快速搭建 百度小程序開發(fā)平臺源碼系統(tǒng)提供了海量的模板,涵蓋了各種行業(yè)和

    2024年01月18日
    瀏覽(41)
  • 【W(wǎng)eb 三件套】個人簡單博客系統(tǒng)頁面搭建(附源碼)

    【W(wǎng)eb 三件套】個人簡單博客系統(tǒng)頁面搭建(附源碼)

    以下為個人搭建的一個簡單博客系統(tǒng)頁面,以后會不斷改進,并且與后端結(jié)合,形成一個完整的博客系統(tǒng) 該博客系統(tǒng)頁面是由 HTML + CSS + JavaScript 搭建的,如果沒有了解過這些知識的友友,可以通過本人之前寫好的幾篇相關(guān)文章入門 文章一: 《超多動圖帶你入門 HTML》 文章二

    2024年02月02日
    瀏覽(26)
  • HTML+CSS+ElementUI搭建個人博客靜態(tài)頁面展示(純前端)

    HTML+CSS+ElementUI搭建個人博客靜態(tài)頁面展示(純前端)

    登錄頁面 門戶頁面 博客頁面 技術(shù)選取: HTML/CSS + VUE2 + ElementUI(Version - 2.15.14) 編程軟件: VSCode 環(huán)境配置與搭建 安裝指令 ELement 在 node 下載后,會發(fā)現(xiàn) node_modules/element-ui 文件夾,直接復(fù)制到本地,之后按照文件路徑引用并配置 [1]ElementUI - 2.15.14官網(wǎng) [2] 獲取圖片網(wǎng)址 [3] 登錄頁面獲

    2024年02月05日
    瀏覽(28)
  • 博客園如何設(shè)置自定義主題?

    博客園如何設(shè)置自定義主題?

    作者:西瓜程序猿 主頁傳送門:https://www.cnblogs.com/kimiliucn 寫博客也有一個月了,發(fā)現(xiàn)博客園自帶的主題都不太好看,然后搜索了一下發(fā)現(xiàn)這款主題【Cnblogs-Theme-SimpleMemory】界面還挺好看的,也是開源的。那[西瓜程序猿]就以這個主題來介紹一下如何在博客園中進行配置,跟著

    2024年02月10日
    瀏覽(31)
  • 搭建個人博客詳細教程

    搭建個人博客詳細教程

    由于國外的github page訪問總是非常慢的,本文選擇國內(nèi)開源代碼托管平臺碼云,因而可以在國內(nèi)搭建訪問與SEO檢索都優(yōu)于GitHub的個人網(wǎng)站。自己親手勉強搭起個人博客,首先感謝木千之博主的詳細教程,給了清晰的思路,寫下這篇博客將詳細過程記錄,希望幫助更多的人,減

    2023年04月08日
    瀏覽(35)
  • gitee搭建個人博客教程

    gitee搭建個人博客教程

    基礎(chǔ)環(huán)境: gitee賬號、git、node.js、npm、Typora(需要版本高一點) 個人博客 創(chuàng)建賬號同名的倉庫 獲取賬號名方式如下,去掉@號的部分。 創(chuàng)建一個和你gitee賬號同名的倉庫,這樣就可以用https://賬號名.gitee.io/來訪問。 填寫倉庫名稱即可,但建議勾選上設(shè)置模板----Readme文件。

    2024年02月09日
    瀏覽(24)
  • Hexo+Github博客搭建教程

    Hexo+Github博客搭建教程

    注意,這篇文章篇幅較長,主要針對新手,每一步很詳細,所以可能會顯得比較啰嗦,所以建議基礎(chǔ)比較好小伙伴根據(jù)目錄選擇自己感興趣的部分跳著看,不要文章沒看,上來先噴一下!謝謝*[Math Processing Error]⊙o⊙*。 教程內(nèi)容隨意復(fù)制使用,引用的話請加一個參考鏈接,謝

    2024年01月16日
    瀏覽(17)
  • 【博客693】alertmanager如何自定義告警template

    template功能: https://prometheus.io/blog/2016/03/03/custom-alertmanager-templates/ 默認(rèn)的template: https://github.com/prometheus/alertmanager/blob/main/template/default.tmpl 配置template: 自定義template模版: 效果: 告警觸發(fā) 告警恢復(fù)

    2024年02月13日
    瀏覽(21)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包