Skip to content

Commit

Permalink
Merge pull request #11 from chollinger93/feat/no-code-in-wordcount
Browse files Browse the repository at this point in the history
Do not count code blocks in WordCount
  • Loading branch information
chollinger93 authored Jun 19, 2023
2 parents 9308aec + 55db991 commit 2c2e2fb
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 58 deletions.
5 changes: 5 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ name = "Github"
icon = "github"
url = "https://github.com/chollinger93/"

[[params.social]]
name = "Twitter"
icon = "twitter"
url = "https://twitter.com/chollinger93/"

[[params.social]]
name = "RSS"
icon = "rss"
Expand Down
55 changes: 30 additions & 25 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
@@ -1,91 +1,96 @@
<!DOCTYPE html>
<html>
{{ partial "header.html" . }}

<body>
<div class="container wrapper">
{{ partial "head.html" . }}

<div class="post">
<div class="post-header">
{{ if ne .Date.Year 1 }}
<div class="meta">
<div class="date">
<span class="day">{{ dateFormat "02" .Date }}</span>
<span class="rest">{{ if $.Site.Data.month }}{{ index $.Site.Data.month (printf "%d" .Date.Month) }} {{ .Date.Year }}{{ else }}{{ dateFormat "Jan 2006" .Date }}{{ end }}</span>
</div>
<div class="meta">
<div class="date">
<span class="day">{{ dateFormat "02" .Date }}</span>
<span class="rest">{{ if $.Site.Data.month }}{{ index $.Site.Data.month (printf "%d"
.Date.Month) }} {{ .Date.Year }}{{ else }}{{ dateFormat "Jan 2006" .Date }}{{ end }}</span>
</div>
</div>
{{ end }}
<div class="matter">
<h1 class="title">{{ .Title }}</h1>
</div>
</div>


{{ if and (gt .WordCount 400 ) (.Site.Params.toc) (ne .Params.toc false) }}
<aside class="toc">
<header>
<h2>Contents</h2>
<h2>Contents</h2>
</header>
{{.TableOfContents}}
</aside>
{{ end }}

<div class="markdown">
{{ .Content }}
</div>

<div class="tags">
{{ if ne .Type "page" }}
{{ if gt .Params.tags 0 }}
<ul class="flat">
{{ range .Params.tags }}
<li class="tag-li"><a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</a></li>
{{ end }}
</ul>
{{ if gt .Params.tags 0 }}
<ul class="flat">
{{ range .Params.tags }}
<li class="tag-li"><a href="{{ " /tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</a></li>
{{ end }}
</ul>
{{ end }}
{{ end }}
</div>

{{ if isset .Site.Params "github" }}
<div class="back">
<a href="{{ .Site.Params.github }}/blob/master/content/{{ .File.Path }}" title="github"><i data-feather="github"></i> Edit this on GitHub</a>
<a href="{{ .Site.Params.github }}/blob/master/content/{{ .File.Path }}" title="github"><i
data-feather="github"></i> Edit this on GitHub</a>
</div>
{{ end }}

<div class="back">
<a href="{{ $.Site.BaseURL }}"><span aria-hidden="true">← Back</span></a>
</div>


<div class="back">
{{ if isset .Site.Params "footers" }}
{{ if ne .Type "page" }}
Next time, we'll talk about <i>"{{ range .Site.Params.footers | shuffle | first 1 }}{{ . }}"</i>{{ end }}
{{ end }}
{{ if ne .Type "page" }}
Next time, we'll talk about <i>"{{ range .Site.Params.footers | shuffle | first 1 }}{{ . }}"</i>{{ end
}}
{{ end }}
{{ end }}
</div>

{{- if .Site.DisqusShortname -}}
{{- $.Scratch.Set "isDisqus" true -}}

{{- if and (isset .Params "type") (in .Site.Params.disableDisqusTypes .Params.type) -}}
{{- $.Scratch.Set "isDisqus" false -}}
{{- $.Scratch.Set "isDisqus" false -}}
{{- end -}}

{{- if and (isset .Params "disqus") (eq .Params.disqus false) -}}
{{- $.Scratch.Set "isDisqus" false -}}
{{- $.Scratch.Set "isDisqus" false -}}
{{- else if and (isset .Params "disqus") (eq .Params.disqus true) -}}
{{- $.Scratch.Set "isDisqus" true -}}
{{- $.Scratch.Set "isDisqus" true -}}
{{- end -}}

{{- if eq ($.Scratch.Get "isDisqus") true -}}
{{- partial "disqus.html" . -}}
{{- end -}}
{{- end -}}
</div>

</div>

{{ partial "footer.html" . }}
</body>

</html>
76 changes: 43 additions & 33 deletions layouts/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html {{- if (eq .Site.Params.mode "dark") -}}class="dark"{{ end }}>
<html {{- if (eq .Site.Params.mode "dark" ) -}}class="dark" {{ end }}>
{{ partial "header.html" . }}

<body>
<div class="container wrapper">
{{ partial "head.html" . }}
Expand All @@ -10,47 +11,56 @@
{{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
{{ $paginator := .Paginate (where $pages "Params.hidden" "ne" true) }}
{{ range $paginator.Pages }}
<div class="post">
<div class="post-header">
<div class="meta">
<div class="date">
<span class="day">{{ dateFormat "02" .Date }}</span>
<span class="rest">{{ if $.Site.Data.month }}{{ index $.Site.Data.month (printf "%d" .Date.Month) }} {{ .Date.Year }}{{ else }}{{ dateFormat "Jan 2006" .Date }}{{ end }}</span>
</div>
<div class="post">
<div class="post-header">
<div class="meta">
<div class="date">
<span class="day">{{ dateFormat "02" .Date }}</span>
<span class="rest">{{ if $.Site.Data.month }}{{ index $.Site.Data.month (printf "%d"
.Date.Month) }} {{ .Date.Year }}{{ else }}{{ dateFormat "Jan 2006" .Date }}{{ end
}}</span>
</div>
<div class="matter">
<h4 class="title small">
<a href="{{ .RelPermalink }}">{{.Title}}{{ if .Draft }}<sup class="draft-label">DRAFT</sup>{{ end }}</a>
</h4>
<h4 class="title small smaller">
{{ .WordCount | lang.FormatNumberCustom 0 }} words, ~{{ div .WordCount .Site.Params.wpm }} min read
</h4>
<h4 class="title small smaller">
{{ if gt .Params.tags 0 }}
<ul class="tags flat">
{{ range first .Site.Params.maxTags .Params.tags }}
<li class="tag-li"><a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</a></li>
{{ end }}
</ul>
{{ end }}
</h4>
<span class="description">
{{ if isset .Params "description" }}
{{ .Description }}
{{ else if gt (len .RawContent) 120 }}
{{ slicestr .RawContent 0 120 }}...
{{ else }}
{{ .RawContent }}
</div>
<div class="matter">
<h4 class="title small">
<a href="{{ .RelPermalink }}">{{.Title}}{{ if .Draft }}<sup
class="draft-label">DRAFT</sup>{{ end }}</a>
</h4>
{{ $wordCountNoCode := replaceRE `(?s)<div class="highlight">.*?</div>` "" .Content |
countwords }}
<h4 class="title small smaller">
{{ $wordCountNoCode | lang.FormatNumberCustom 0 }} words, ~{{ div .WordCount
.Site.Params.wpm
}} min read
</h4>
<h4 class="title small smaller">
{{ if gt .Params.tags 0 }}
<ul class="tags flat">
{{ range first .Site.Params.maxTags .Params.tags }}
<li class="tag-li"><a href="{{ " /tags/" | relLangURL }}{{ . | urlize }}">{{ .
}}</a></li>
{{ end }}
</span>
</div>
</ul>
{{ end }}
</h4>
<span class="description">
{{ if isset .Params "description" }}
{{ .Description }}
{{ else if gt (len .RawContent) 120 }}
{{ slicestr .RawContent 0 120 }}...
{{ else }}
{{ .RawContent }}
{{ end }}
</span>
</div>
</div>
</div>
{{ end }}
{{ template "partials/paginator.html" . }}
</div>
</div>
</div>
{{ partial "footer.html" . }}
</body>

</html>

0 comments on commit 2c2e2fb

Please sign in to comment.