Hugo [] - hugo listeners to switch browser title

hugo blog browser title listener dynamically change the browser title title

Find head.html

themes/maupassant/layouts/partials/head.html

Add a listener js

Can be found from html, the home page and other pages are divided into two different shows, it is necessary to change the two parts

  {{ if .IsHome -}}
    <title>{{ .Site.Title }} | {{ .Site.Params.subtitle}}</title>
    <meta property="og:title" content="{{ .Site.Title }} | {{ .Site.Params.subtitle}}">
    <meta property="og:type" content="website">
    <meta name="Keywords" content="{{.Site.Params.keywords}}">
    <meta name="description" content="{{ .Site.Params.description }}">

<!--添加部分-start-->

    <script>
    document.addEventListener('visibilitychange',function(){
        if( document.visibilityState == 'hidden' ){
        normal_title = document.title;
        document.title = 'ヽ(●-`Д´-)ノ你丑你就走!';
        }else{
        document.title = 'ヾ(Ő∀Ő3)ノ你帅就回来!';
        setTimeout(function(){
            document.title = normal_title;
        }, 1200)
        }
    });
    </script>
<!--添加部分-end-->

    {{- else -}}
    <title>{{ .Title }} | {{ .Site.Title }}</title>

<!--添加部分-start-->
    <script>
    document.addEventListener('visibilitychange',function(){
        if( document.visibilityState == 'hidden' ){
        normal_title = document.title;
        document.title = 'ヽ(●-`Д´-)ノ你丑你就走!';
        }else{
        document.title = 'ヾ(Ő∀Ő3)ノ你帅就回来!';
        setTimeout(function(){
            document.title = normal_title;
        }, 1200)
        }
    });
    </script>
    <!--添加部分-end-->

Guess you like

Origin www.cnblogs.com/somliy/p/12242505.html