4月4日 ssr项目首页置灰

1.首先设置使html变灰的样式。

const HtmlGrayStyle = `
<style type="text/css">
html {
  filter: grayscale(100%);
  -webkit-filter: grayscale(100%);
  -moz-filter: grayscale(100%);
  -ms-filter: grayscale(100%);
  -o-filter: grayscale(100%);
  filter: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='grayscale'><feColorMatrix type='matrix' values='0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0'/></filter></svg>#grayscale"); filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
  -webkit-filter: grayscale(1);
}
</style>
`

2.在render的中间件里面判断时间

if (now >= 1585929600000 && now <= 1586016000000 && lang === 'zh_CN') {
        htmlStyle = HtmlGrayStyle
     }

3.将变量插入到html

 <meta name="description" itemprop="description" content="{{@ description || ''}}" />
    {{@ htmlStyle || ''}}

 

 

posted @ 2020-04-04 00:28  李元夕cool  阅读(26)  评论(0编辑  收藏  举报