跳到主要內容

meta tag 說明

meta tag 說明

1. <title></title>
*建議中文保持在 30 個字元、英文 60 個字元以內
*可以用以下格式: 主要關鍵字  -  次要關鍵字 | 廠牌名稱
*每個頁面的 Title 都是唯一的
<title>MyDemo-@ViewData["Title"]</title>

2. <meta name='description' content='@ViewData["PageDescript"]' />
*建議中文保持在 80 個字元、英文 160 個字元以內

3. og 社群相關 tag
og 全名為: Open Graph Protocol
*在 og:title 設定的文字會當作分享 FB 時的標題。

3.1 og:image
*大小不要超過 8 m
*尺寸要大於 200px * 200px,否則連圖都抓不到
*如果圖片為長方形 建議最小尺寸 600px * 315px
*如果圖片為正方形 建議最小尺寸 600px * 600px


程式化新增 meta tag



//在DotNet Core Project中 新增目錄夾 Filters ,並新增MetaTagFilter.cs 檔案 

using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc;

namespace WebProject.Filters
{

    public class MetaTagAttribute : TypeFilterAttribute { 
        public MetaTagAttribute( ) : base( typeof( MetaTagFilter ) ) {

        } 

        public class MetaTagFilter : IActionFilter { 
            
            private string title { get; set; } 
            private string description { get; set; } 
            private string image { get; set; } 
            private string robotRule { get; set; } 
            public MetaTagFilter( ) : this( 
              title: "MyDemo" , 
              description: "" , 
              image: "" ,
              robotRule: "index,follow" ) { }

              public MetaTagFilter(string title , string description , string image , string robotRule ) { 
              this.title = title ?? this.title; 
              this.description = description ?? this.description; 
              this.image = image ?? this.image; 
              this.robotRule = robotRule ?? this.robotRule;
            } 

            public void OnActionExecuted( ActionExecutedContext context ) { 

            } 

            public void OnActionExecuting( ActionExecutingContext context ) { 
              dynamic controller = context.Controller; 
              controller.ViewBag.Title = this.title; 
              controller.ViewBag.Description = this.description; 
              controller.ViewBag.image = this.image; 
              controller.ViewBag.RobotRule = this.robotRule; 
            } 
        } 
    } 
}

//在DotNet Core Project中 Controller 目錄夾下 *.cs  
[MetaTag( Arguments = new object[] {"${title}","${description}","${image url}","${robot rules}" } )] 
public IActionResult Index()
{
  return View();
}

//在DotNet Core Project中 Shared 目錄夾下 _Layout.cshtml 
<head>
    <title>MyDemo-@Html.Raw(ViewBag.Title)</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name='description' content='@Html.Raw(ViewBag.Description)' />
    <meta name='robot' content='@ViewBag.RobotRule' />
    <meta property='og:title' content='MyDemo-@Html.Raw(ViewBag.Title)' />
    <meta property='og:description' content='@Html.Raw(ViewBag.Description)' />
    <meta property='og:image' content='@ViewBag.image' />
    <meta property='og:type' content='website' />
    <meta property='og:url' content='@Context.Request.GetDisplayUrl()' />
    <meta property='og:site_name' content='MyDemo' />
    <meta http-equiv="Content-Language" content="zh-tw" />
    <meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
</head>

留言

這個網誌中的熱門文章

Grafana Dashboard 建立

建立自己的 Dashboard # 由於 intelligent sense 相當不錯,輸入關鍵字他會帶出 metric label # 另外可參考 https://prometheus.io/docs/prometheus/latest/querying/basics/ Prometheus Query # 或是直接拿其他已建立的Dashboard 可複製到新的 Dashboard ex: node_memory_MemTotal_bytes # 取伺服器記憶體容量資料 # 過濾條件在{}加入 ex: node_memory_MemTotal_bytes{instance="${server 1}:9100"} # 要取特定伺服器資料 # Setting 中設定 Variables ex: node_memory_MemTotal_bytes{instance=~"$node"} # 變數名稱 node 建立 Alert .Visualization 必須是Graph

FluentD 參數說明

FluentD 高效、統一的日誌收集器 延伸閱讀 FluentD 實作 Nginx Access Log FluentD 實作 Nginx Access Log 補充 FluentD 安裝 Dockerfile FROM fluent/fluentd:v1.8.1-1.0 # Use root account to use apk USER root # below RUN includes plugin as examples elasticsearch is not required # you may customize including plugins as you wish RUN apk add --no-cache --update --virtual .build-deps \ sudo build-base ruby-dev \ && apk add mariadb-dev \ && sudo gem install fluent-plugin-elasticsearch \ && sudo gem install fluent-plugin-mongo \ && sudo gem install fluent-plugin-sql \ && sudo gem install mysql2 -v 0.5.2 \ && sudo gem sources --clear-all \ && apk del .build-deps \ && rm -rf /home/fluent/.gem/ruby/2.5.0/cache/*.gem VOLUME ["/fluentd/etc","/fluentd/log","/var/log"] docker-compose.yml version: '3' services: fluentd: build: context: . dockerfile: ./Dockerfile image: my/flue...

FluentD 實作 Nginx Access Log 補充

FluentD 實作 Nginx Access Log 補充 前一篇針對 FluentD 安裝 及 Nginx Access log format 設定提供範例 本篇補充 1. 將 access_log 存入 MySQL 2. 針對Input 加工,ex 解析 Path 拆成不同欄位,在傳入 Output 延伸閱讀 FluentD 參數說明 FluentD 實作 Nginx Access Log 將 access_log 存入 MySQL <worker 0> <source> ... 略 </source> <match nginx.web.access> @type copy ... 略 <store> @type sql host ${MySQL Host address} port ${MySQL Port} adapter mysql2 database ${MySQL Database} username ${MySQL User Name} password ${MySQL Password} <table> table ${MySQL table} column_mapping 'logtime:logtime,method:method,path:path,code:code,size:size,resptime:resptime,token:token,path_url:path_url,timestamp:created_at' </table> </store> </match> </worker> 針對Input 加工,ex 解析 Path 拆成不同欄位,在傳入 Output 情境: 以下 access log 範例,需要針對 Query Parameter 拆解並存入新欄位,以利分析. [27/Dec/2019:07:14:10 ...