#!/bin/bash
# Create the basic four files:
#   * styling
#   * nav bar
#   * index page
#   * template
mkdir -p _static
cat > _static/style.css << EOF
body {
  font-family: system-ui;
  max-width: 70ch;
  padding: 2ch;
  margin: auto;
  color: #222;
  background: #fed;
}
a{color:#a44}
a:visited{color:#555}
img{max-width:100%}
pre{overflow:auto}
table,th,td{border:1px solid;padding:.5rem;border-collapse: collapse}

nav ul{display: none; list-style: none; padding: 0}
nav #checkbox{opacity: 0}
nav #checkbox:checked + ul{display: block
EOF

cat > nav.md << EOF
* [home](/)
* [blog](/blog)
* [research](/research)
EOF

cat > index.p.md << EOF
# Homepage
Welcome to my site!

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud [exercitation](https://wikipedia.org) ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
EOF

cat > p.template.html << EOF
!!# Default 'Page' Template
!!#=========================
!!# See pp(1) for syntax: !!
!!# See 'ppages help' for templating documentation
<!DOCTYPE html>
<html lang=en>
<head>
!! echo "<title>\$TITLE</title>"
    </title>
    <meta charset=utf-8>
!! echo "<meta name=author content=\"\$AUTHOR\" name=author>"
    <meta name=viewport content="width=device-width,initial-scale=1">
    <link rel="shortcut icon" href="/favicon.svg"/>
    <link rel="stylesheet" type="text/css" href="/style.css">
</head>
<body>
<header style="display:flex;justify-content:space-between">
    <h1 style="display:inline-block;font-size:1rem;margin-top:0.25em">
!! echo "<a href="/">\$TITLE</a>"
    </a>
    </h1>
!!# The nav bar is compiled from a file if it exists
!! [ ! -f nav.md ] || echo '<nav style="display:inline-block;-webkit-user-select:none">'
!! [ ! -f nav.md ] || echo ' <label style="padding: 5px;outline: 1px solid" for="checkbox">Menu ▼</label>'
!! [ ! -f nav.md ] || echo ' <input id="checkbox" type="checkbox" />'
!! [ ! -f nav.md ] || cmark nav.md
!! [ ! -f nav.md ] || echo '</nav>'
</header>
!!# Below we are piping the found *.<type>.md file through pandoc
!!#   <type> in this file's name comes from <type>.template.html
!! pandoc < \$PAGE
</body>
!!# Optional footer with link to the generator
<footer style="margin: 4em auto; text-align:right">
<hr>
<p>built with <a href="https://github.com/jhjn/ppages">ppages</a></p>
</footer>
</html
EOF

echo "Success! Now 'curl -sL jenne.uk/ppages | bash'"
