{{ define "main" }}
<div id="data-pid" style="display:none">{{ .RelPermalink }}</div>
<article style="margin-bottom:1.5em">
<h1 class="post-title" itemprop="name headline" uk-scrollspy="cls: uk-animation-slide-top-small; delay: 200">{{ .Title }}</h1>
<div class="meta" uk-scrollspy="cls: uk-animation-slide-bottom-small; delay: 300">
<span class="meta-item">作者: {{ .Site.Params.author | default "博主" }}</span>
<span class="meta-item">浏览: <span id="busuanzi_value_page_uv"></span></span>
<span class="meta-item">字数: <span id="word-count">{{ .WordCount }}</span></span>
<span class="meta-item meta-item-reading-time">阅读: 约 <span id="reading-time">{{ .ReadingTime }}</span> 分钟</span>
{{ with .Params.categories }}<span class="meta-item">分类:{{ range . }} <a href="{{ "archives/" | absURL }}">{{ . }}</a>{{ end }}</span>{{ end }}
</div>
<div class="post-content" id="post-writing" itemprop="articleBody">
{{ .Content }}
</div>
{{ if or .PrevInSection .NextInSection }}
<div class="post-nav">
{{ with .PrevInSection }}
<a class="post-nav-prev" href="{{ .RelPermalink }}">
<span class="post-nav-label">←</span>
<span class="post-nav-title">{{ .Title }}</span>
</a>
{{ end }}
{{ with .NextInSection }}
<a class="post-nav-next" href="{{ .RelPermalink }}">
<span class="post-nav-label"></span>
<span class="post-nav-title">{{ .Title }}</span>→
</a>
{{ end }}
</div>
{{ end }}
<hr class="uk-divider-icon">
{{ if .Site.Params.artalk }}
<div id="Comments"></div>
<div id="artalk_container"></div>
{{ end }}
</article>
{{ end }}

{{ define "scripts" }}
<script>
(function(){
  var el = document.getElementById('post-writing');
  if (!el) return;
  var text = el.innerText || el.textContent || '';
  // Count CJK characters individually
  var cjk = (text.match(/[\u4e00-\u9fff\u3400-\u4dbf\uf900-\ufaff]/g) || []).length;
  // Count English/number words
  var en = (text.match(/[a-zA-Z0-9]+/g) || []).length;
  var total = cjk + en;
  var wcEl = document.getElementById('word-count');
  if (wcEl) wcEl.textContent = total;
  // Reading speed: ~400 CJK chars/min or ~200 EN words/min
  var minutes = Math.max(1, Math.ceil(cjk / 400 + en / 200));
  var rtEl = document.getElementById('reading-time');
  if (rtEl) rtEl.textContent = minutes;
})();
</script>
{{ if .Site.Params.artalk }}
<script>
window.loadScriptOnce&&loadScriptOnce("{{ "js/libs/Artalk.min.js" | absURL }}","Artalk",function(){
new Artalk({el:"#artalk_container",pageKey:"{{ .Permalink }}",pageTitle:"{{ .Title }}",server:"{{ .Site.Params.artalkServer }}",site:"{{ .Site.Title }}"})});
</script>
{{ end }}
{{ end }}
