跳到主要內容

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>

留言

這個網誌中的熱門文章

FluentD 實作 Error Log

FluentD 實作 Error Log 本篇將介紹使用 DotNet 專案 log4net 套件,紀錄的 log 針對 Error Level 的訊息透過FluentD 提取出來 在紀錄中 增加 trace ID 設入 MongoDB , 及加入 Slack 通知 延伸閱讀 FluentD 參數說明 FluentD 實作 Nginx Access Log FluentD 實作 Nginx Access Log 補充 log4net <?xml version="1.0" encoding="utf-8" ?> <configuration> <log4net> <appender name="All" type="log4net.Appender.RollingFileAppender"> <file value="/var/log/my.log" /> <appendToFile value="true" /> <rollingStyle value="Size" /> <datePattern value="yyyy-MM-dd" /> <maximumFileSize value="5MB" /> <maxSizeRollBackups value="10" /> <staticLogFileName value="true" /> <PreserveLogFileNameExtension value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="[%date] [...

DotNet Core 專案部署腳本

DotNet core SDK 首先在 Server 上準備編譯環境 Dockerfile #2.2 3.0 3.1 FROM mcr.microsoft.com/dotnet/core/sdk:3.1 RUN mkdir /web WORKDIR /web build docker image shell script docker build -t dotnetcoresdk:3.1 . start docker container shell script docker run -it -d \ --name dotnet-core-sdk-3.1 \ -v /opt/web:/web \ dotnetcoresdk:3.1 Jenkins Execute shell script on remote hosting using ssh #切換至專案目錄 cd /opt/web/project/path #取得最新版本 git pull #切換至專案目錄 && 刷新 Dotnet Library docker exec -i dotnet-core-sdk-3.1 bash -c "cd project/path && dotnet restore" #切換至專案目錄 && 刪除上一次編譯的檔案 && 編譯 docker exec -i dotnet-core-sdk-3.1 bash -c "cd project/path && rm -rf bin/Release && dotnet publish -c Release" #docker-compose.yml 參 DotNet core Runtime Section #!--rmi all 將原本執行的容器關閉並移除Image docker-compose down --rmi all #將新版程式包入 Image 並開始容器 docker-compose up -d DotNet core Runtime 專案中包含 Dockerfile & docker-compose.yml d...

Prometheus + Grafana + Exporters = Server Monitor

Grafana 功能強大且美觀的Dashboard Prometheus 用來作為數據收集及儲存,透過設定至各 exporter 端"拉"資料回來 exporter Prometheus exporter 環境建置 使用 docker-compose 時,會依所在目錄建立 ${path}-default docker network 純粹為了賞心悅目 建立一個 monitor-net 集中堆放 Grafana , Prometheus , xxxx exporter 建立 docker network docker network create monitor-net Grafana + Prometheus docker-compose.yml version: '3' services: grafana: image: grafana/grafana ports: - 9000:9000 - 9010:3000 environment: - GF_SERVER_ROOT_URL= - GF_SECURITY_ADMIN_PASSWORD= volumes: # copy grafana.ini to /etc/grafana - /etc/grafana/grafana.ini:/etc/grafana/grafana.ini - /var/lib/grafana:/var/lib/grafana - /var/log/grafana:/var/log/grafana container_name: my-grafana restart: always networks: - myonitornet prometheus: image: prom/prometheus ports: - 9090:9090 volumes: # copy prometheus.yml to /etc/prometheus - /etc/prometheus/prometheus.yml:/etc/prome...