#lang pollen/mode racket/base

;; Copyright (c) 2018 Joel Dueck.
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; A copy of the License is included with this source code, in the
;; file "LICENSE.txt".
;; You may also obtain a copy of the License at
;;
;;       http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
;;
;; Author contact information:
;;   joel@jdueck.net
;;   https://joeldueck.com
;; -------------------------------------------------------------------------

;; Provides functions for displaying content in HTML templates.
(require pollen/core
         "dates.rkt")

(provide (all-defined-out))

(define (html-head [title #f])
  ◊@{<head>
     <title>The Local Yarn◊when/splice[title]{: ◊title}</title>
     <meta charset="utf-8" />
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <link rel="stylesheet" type="text/css" href="/web-extra/martin.css">
     </head>})

(define (html-page-top)
  ◊@{<body><main>
     <a href="/"><header>
     <img src="/web-extra/logo.png" height="103" width="129" class="logo">
     <h1>The Local Yarn</h1>
     </header></a>})

(define (html-article-header)
  (define title (select-from-metas 'title (current-metas)))
  (define published (select-from-metas 'published (current-metas)))
    (cond
      [title
       ◊string-append{<article class="with-title hentry">
          <h1 class="entry-title">◊|title|</h1>
          <p class="time"><a href="#" class="rel-bookmark">
          <time datetime="◊published" class="published">◊ymd->english[published]</time>
          </a></p>
          <section class="entry-content">}]
      [else
       ◊string-append{<article class="no-title hentry">
          <h1><a href="#" class="rel-bookmark">
          <time datetime="◊published" class="entry-title">◊ymd->english[published]</time>
          </a></h1>
          <section class="entry-content">}]))

(define (html-article-footer)
  ◊string-append{</section>
     <footer class="article-info"><span class="x">(</span>Part of ‘Talking About Poetry’. Once I threw a mudball at a birdhouse. I’m not exactly proud of it, though.<span class="x">)</span></footer>
     </article>})


(define (html-page-bottom)
  ◊@{<footer>By Joel Dueck</footer>
     </main></body>})