add adsense option

This commit is contained in:
~m 2023-12-03 22:18:59 +07:00
parent b288ede80c
commit cfb5c01418
12 changed files with 58 additions and 0 deletions

View File

@ -61,6 +61,7 @@
</div> </div>
{{- end }} {{- end }}
</div> </div>
{{- partial "adsense-infeed.html" $ -}}
{{- end }} {{- end }}
{{- end }} {{- end }}

View File

@ -53,6 +53,7 @@
{{- if (.Param "comments") }} {{- if (.Param "comments") }}
{{- partial "comments.html" . }} {{- partial "comments.html" . }}
{{- end }} {{- end }}
{{ partial "adsense-multiplex.html" $ }}
</article> </article>
{{- end }}{{/* end main */}} {{- end }}{{/* end main */}}

View File

@ -0,0 +1,10 @@
<!-- ad-display -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="{{- .Site.Params.adsense.clientID -}}"
data-ad-slot="{{- .Site.Params.adsense.slotDisplay -}}"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

View File

@ -0,0 +1,10 @@
<!-- ad-in-article -->
<ins class="adsbygoogle"
style="display:block; text-align:center;"
data-ad-layout="in-article"
data-ad-format="fluid"
data-ad-client="{{- .Site.Params.adsense.clientID -}}"
data-ad-slot="{{- .Site.Params.adsense.slotInArticle -}}"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

View File

@ -0,0 +1,16 @@
<!-- ad-in-feed -->
<ins class="adsbygoogle"
style="display:block"
data-ad-format="fluid"
data-ad-layout-key="-gw-3+1f-3d+2z"
data-ad-client="{{- .Site.Params.adsense.clientID -}}"
data-ad-slot="{{- .Site.Params.adsense.slotInFeed -}}"></ins>
<!-- <ins class="adsbygoogle imgtheme-dark"
style="display:block"
data-ad-format="fluid"
data-ad-layout-key="-gw-3+1f-3d+2z"
data-ad-client="{{- .Site.Params.adsense.clientID -}}"
data-ad-slot="{{- .Site.Params.adsense.slotInFeedDark -}}"></ins> -->
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

View File

@ -0,0 +1,9 @@
<!-- ad-multiplex -->
<ins class="adsbygoogle"
style="display:block"
data-ad-format="autorelaxed"
data-ad-client="{{- .Site.Params.adsense.clientID -}}"
data-ad-slot="{{- .Site.Params.adsense.slotMultiplex -}}"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

View File

@ -167,4 +167,5 @@
{{- template "partials/templates/opengraph.html" . }} {{- template "partials/templates/opengraph.html" . }}
{{- template "partials/templates/twitter_cards.html" . }} {{- template "partials/templates/twitter_cards.html" . }}
{{- template "partials/templates/schema_json.html" . }} {{- template "partials/templates/schema_json.html" . }}
{{- template "partials/templates/adsense.html" . }}
{{- end -}} {{- end -}}

View File

@ -0,0 +1,6 @@
{{ $adsenseEnabled := (and .Site.Params "adsense" (ne .Params.disableAdsense true) ) }}
{{ $adsenseAllowedOnPage := (ne .Kind "404" )}}
{{- if (and $adsenseEnabled $adsenseAllowedOnPage) }}
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client={{- .Site.Params.adsense.clientID -}}" crossorigin="anonymous"></script>
{{- end }}

View File

@ -0,0 +1 @@
{{ partial "adsense-inarticle.html" $ }}

View File

@ -0,0 +1 @@
{{ partial "adsense-display.html" $ }}

View File

@ -0,0 +1 @@
{{ partial "adsense-infeed.html" $ }}

View File

@ -0,0 +1 @@
{{ partial "adsense-multiplex.html" $ }}