You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by wa...@apache.org on 2022/11/11 09:01:23 UTC

[echarts-handbook] branch master updated: add page title

This is an automated email from the ASF dual-hosted git repository.

wangzx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/echarts-handbook.git


The following commit(s) were added to refs/heads/master by this push:
     new 944c434  add page title
944c434 is described below

commit 944c434620a6b3cee0d905b2482cf34a0ed429db
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Fri Nov 11 17:00:48 2022 +0800

    add page title
---
 components/partials/Sidebar.vue |  2 +-
 nuxt.config.js                  |  5 ++++-
 pages/_.vue                     | 30 +++++++++++++++++++++++++++---
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/components/partials/Sidebar.vue b/components/partials/Sidebar.vue
index 8202c17..9fd6017 100644
--- a/components/partials/Sidebar.vue
+++ b/components/partials/Sidebar.vue
@@ -26,7 +26,7 @@
     <div class="bd-docs-nav">
       <ul class="nav bd-sidenav nav-root level0">
         <SidebarNavItem
-          v-for="level0Post in $store.state.posts[this.$i18n.locale]"
+          v-for="level0Post in $store.state.posts[$i18n.locale]"
           :key="level0Post.dir"
           :item="level0Post"
           :parentPath="''"
diff --git a/nuxt.config.js b/nuxt.config.js
index c5773d7..fddb8fe 100644
--- a/nuxt.config.js
+++ b/nuxt.config.js
@@ -5,6 +5,9 @@ if (process.env.NODE_ENV === 'production') {
   console.log('Deploying to ...', process.env.NUXT_ENV_DEPLOY)
 }
 
+/**
+ * @type {import('@nuxt/types').NuxtConfig}
+ */
 export default {
   ssr: true,
 
@@ -40,7 +43,7 @@ export default {
    ** Headers of the page
    */
   head: {
-    title: 'Handbook - Apache ECharts',
+    titleTemplate: chunk => `${chunk ? chunk + ' - ' : ''}Handbook - Apache ECharts`,
     meta: [
       { charset: 'utf-8' },
       { name: 'viewport', content: 'width=device-width, initial-scale=1' },
diff --git a/pages/_.vue b/pages/_.vue
index 2d260f2..2579a1b 100644
--- a/pages/_.vue
+++ b/pages/_.vue
@@ -82,6 +82,25 @@ function slugify(s: string) {
   )
 }
 
+function findPostByDir(posts: any[], dir: string) {
+  for (let i = 0, len = posts.length, post; i < len; i++) {
+    post = posts[i]
+    if (post.dir === dir) {
+      return post
+    }
+  }
+}
+
+function composePostTitle(posts: any[], path: string) {
+  const parts: string[] = []
+  const slugs = path.split('/')
+  for (let i = 0, post; i < slugs.length; i++) {
+    post = findPostByDir(post ? post.children : posts, slugs[i])
+    post && parts.unshift(post.title)
+  }
+  return parts.join(' - ')
+}
+
 export default {
   components: {
     Contributors,
@@ -128,6 +147,8 @@ export default {
   },
   head() {
     return {
+      // @ts-ignore
+      title: this.title,
       meta: [
         {
           hid: 'docsearch:language',
@@ -138,8 +159,11 @@ export default {
       ]
     }
   },
-  async asyncData({ params, i18n }: any) {
-    const postPath = `${i18n.locale}/${params.pathMatch}`
+  async asyncData({ params, i18n, store }: any) {
+    const posts = store.state.posts[i18n.locale]
+    const path = params.pathMatch;
+    const title = composePostTitle(posts, path);
+    const postPath = `${i18n.locale}/${path}`
     const fileContent = await import(`~/contents/${postPath}.md`)
     const content = replaceVars(
       parseCodeBlocks(parseLiveCodeBlocks(fileContent.default)),
@@ -168,7 +192,7 @@ export default {
         }
       }) // lazyload
 
-    return { html: md.render(content), postPath }
+    return { html: md.render(content), postPath, title }
   }
 }
 </script>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org