|
| 1 | +{%- assign buildAt = site.time | date: "%Y%m%d%H%M%S" -%} |
| 2 | +<head> |
| 3 | + <title>{{ page.title }}-{{ site.title }}</title> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <meta http-equiv="content-language" content="zh-CN" /> |
| 6 | + <meta name="theme-color" content="#ffffff" /> |
| 7 | + <meta name="supported-color-schemes" content="light dark"> |
| 8 | + <meta name="renderer" content="webkit"> |
| 9 | + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| 10 | + <meta name="viewport" content="width=device-width,initial-scale=1" /> |
| 11 | + <meta name="applicable-device" content="pc,mobile"> |
| 12 | + <meta name="author" content="{{ site.author }}" /> |
| 13 | + {%- if page.categories %} |
| 14 | + <meta name="description" content="{{ page.title }}"/> |
| 15 | + <meta name="keywords" content="{{ site.author }}{% for category in page.categories %},{{ category }}{% endfor %}"/> |
| 16 | + {% else %} |
| 17 | + <meta name="description" content="{{ site.description }}"/> |
| 18 | + <meta name="keywords" content="{{ site.keywords }}"/> |
| 19 | + {% endif -%} |
| 20 | + <link rel="icon" href="{{site.baseurl}}/static/img/favicon.ico" /> |
| 21 | + <link rel="apple-touch-icon" href="{{site.baseurl}}/static/img/logo.png" /> |
| 22 | + <link rel="stylesheet" href="{{site.baseurl}}/static/css/common.css?t={{buildAt}}"> |
| 23 | + <link rel="stylesheet" href="{{site.baseurl}}/static/css/theme-dark.css?t={{buildAt}}"> |
| 24 | + {%- if page.layout == "mypost" %} |
| 25 | + <link rel="stylesheet" href="{{site.baseurl}}/static/css/post.css?t={{buildAt}}"> |
| 26 | + <link rel="stylesheet" href="{{site.baseurl}}/static/css/code-dark.css?t={{buildAt}}"> |
| 27 | + <link rel="stylesheet" href="{{site.baseurl}}/static/css/code-light.css?t={{buildAt}}"> |
| 28 | + {%- endif %} |
| 29 | + {%- if page.layout == "page" %} |
| 30 | + <link rel="stylesheet" href="{{site.baseurl}}/static/css/page.css?t={{buildAt}}"> |
| 31 | + {%- endif %} |
| 32 | + <link rel="prefetch" href="{{site.baseurl}}/static/xml/search.xml?t={{ buildAt }}"> |
| 33 | + <link rel="prefetch" href="{{site.baseurl}}/static/js/search.js?t={{ buildAt }}"> |
| 34 | + <script> |
| 35 | + window.blog = { |
| 36 | + baseurl:"{{site.baseurl}}", |
| 37 | + buildAt:"{{buildAt}}", |
| 38 | + darkTheme: false, |
| 39 | + setDarkTheme: function (dark) { |
| 40 | + this.darkTheme = Boolean(dark); |
| 41 | + document.documentElement.className = this.darkTheme ? 'dark': ''; |
| 42 | + document.querySelector('meta[name=theme-color]').setAttribute('content', this.darkTheme ? '#2D2E32': '#FFFFFF'); |
| 43 | + } |
| 44 | + } |
| 45 | + if (sessionStorage.darkTheme !== undefined) { |
| 46 | + blog.setDarkTheme(sessionStorage.darkTheme === 'true'); // 记忆值,单个窗口内有效 |
| 47 | + } else { |
| 48 | + blog.setDarkTheme(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches); // 跟随系统 |
| 49 | + } |
| 50 | + if (window.matchMedia) { |
| 51 | + var media = window.matchMedia('(prefers-color-scheme: dark)'); |
| 52 | + media.addListener(function (ev) { |
| 53 | + blog.setDarkTheme(ev.currentTarget.matches); |
| 54 | + sessionStorage.removeItem('darkTheme'); |
| 55 | + }); |
| 56 | + } |
| 57 | + </script> |
| 58 | +</head> |
0 commit comments