2017-10-14 10 views
1

HEXOブログの場合...メタ記述は設定ファイルに書かれており、すべてのページで動作します。「タグ」と「カテゴリ」ページのメタ記述

blogpostsについては、個別のメタディスクリプションを作成することができます。これは検索エンジンで機能します。

しかし、私の "タグ"と "カテゴリ"ページは、現在、ホームページのメタ記述で索引付けされています。 これは良くありません。

「タグ」と「カテゴリ」ページのカスタムメタデータ記述を作成できるかどうかを尋ねていますか?これは私のhead.ejsのコードである description: this is a page about {{tag}}

description: this is a page about {{category}}

何かのように...。 サイトのメイン設定ファイルはdescription: main config meta-description textです。

<%if(metaDescription){%> 
 
<meta name="description" content="<%= config.description %>"> 
 
    <% } else if (page.description){ %> 
 
     <meta name="description" content="<%= page.description %>"> 
 
     <% } else if (page.excerpt){ %> 
 
     <meta name="description" content="<%= strip_html(page.excerpt).replace(/^\s*/, '').replace(/\s*$/, '').replace(/[\n,\r]/g,'') %>"> 
 
     <% } else if (page.content){ %> 
 
     <meta name="description" content="<%= strip_html(page.content).replace(/^\s*/, '').replace(/\s*$/, '').substring(0, 150).replace(/[\n,\r]/g,'') %>"> 
 
     <% } else if (config.description){ %> 
 
     <meta name="description" content="<%= config.description %>"> 
 
     <% } 
 
     <% if (page.keywords){ %> 
 
     <meta name="keywords" content="<%= page.keywords %>"> 
 
     <% } else if (page.tags){ %> 
 
     <% 
 
     var thistags=[]; 
 
     page.tags.each(function(k){ 
 
     thistags.push(k.name); 
 
     }) %> 
 
     <meta name="keywords" content="<%= thistags %>"> 
 
     <% } %>

答えて

1

あなたがそこにロジックを追加する必要があるので、これはすべてのあなたのテーマによって処理されます。

あなたはあなたのページは、タグやカテゴリのインデックスであるかどうかを確認し、そこに独自の記述を生成する必要があります。

let description = page.description; // Normal case when your desc comes from meta data 


else if (page.tag) { 
    description = 'This is a page about ' + page.tag; 
} else if (page.category) { 
    description = 'This is a page about ' + page.category; 
} 

// Use your description variable as you are currently doing 

EDIT:(head.ejsを追加)後の更新

else if (page.tag) { 
    <meta name="description" content="<%= 'This is a page about ' + page.tag %>"> 
} else if (page.category) { 
    <meta name="description" content="<%= 'This is a page about ' + page.category %>"> 
} 
+0

こんにちはに基づきます..私はすでにあなたのブログからたくさんのことを学びました... http://www.codeblocq.com/2016/03/Create-an-Hexo-Theme-Part-1-Index/ - ここにもお会いできてうれしいです... :)説明については意味がありますが、これを正確に実装する場所はどこですか?私は投稿概要ページを持っており、これは 'archive.ejs'、私の' tags'ページからロジックを受け取り、 'categories'ページも私の' archive.ejs'パーシャルのロジックを取ると仮定して、上のコードを追加します'archieve.ejs'?また、メインの 'config'ファイルに設定しているので、デフォルトの' meta-description'はNON-tagとNON-categoryではまだ動作していますか? – raulbaros

+0

メタ記述が設定から来たら、完璧です。ロジックの残りの部分は、必要な場所に実装する必要があります。おそらく 'head.ejs'などです。 – klugjo

+1

、ありがとう! – raulbaros

関連する問題