Change example site. Make layouts blog friendly

This commit is contained in:
Zachary Betz 2019-02-12 16:25:13 -06:00
parent ac614e6ab5
commit f0179670ed
57 changed files with 1901 additions and 1040 deletions

View File

@ -6,8 +6,8 @@ googleAnalytics = "UA-123456789-1"
# Uncomment below to enable syntax highlighting
# For more styles see https://xyproto.github.io/splash/docs/all.html
# pygmentsCodefences = true
# pygmentsStyle = "algol"
pygmentsCodefences = true
pygmentsStyle = "algol"
[taxonomies]
tag = "tags"
@ -15,6 +15,16 @@ googleAnalytics = "UA-123456789-1"
[permalinks]
post = "/:filename/"
[imaging]
quality = 99
[params]
# description = "An accessibility-friendly Hugo theme, ported from the [original Cupper](https://github.com/ThePacielloGroup/cupper) project."
footer = "Made with [Hugo](https://gohugo.io/). Themed by [Cupper](https://github.com/zwbetz-gh/cupper-hugo-theme). Deployed to [Netlify](https://www.netlify.com/)."
# For more date formats see https://gohugo.io/functions/format/
dateFormat = "Jan 2, 2006"
codePenUser = "TODO"
[menu]
[[menu.nav]]
name = "Home"
@ -36,10 +46,3 @@ googleAnalytics = "UA-123456789-1"
name = "RSS"
url = "/index.xml"
weight = 5
[params]
# description = "An accessibility-friendly Hugo theme, ported from the [original Cupper](https://github.com/ThePacielloGroup/cupper) project."
footer = "Made with [Hugo](https://gohugo.io/). Themed by [Cupper](https://github.com/zwbetz-gh/cupper-hugo-theme). Deployed to [Netlify](https://www.netlify.com/)."
# For more date formats see https://gohugo.io/functions/format/
dateFormat = "Jan 2, 2006"
codePenUser = "TODO"

View File

@ -1,12 +1,14 @@
+++
date = "2017-06-26T18:27:58+01:00"
title = "Home"
+++
---
date: "2017-06-26T18:27:58+01:00"
title: "Home"
---
Welcome to **Cupper**: An accessibility-friendly Hugo theme, ported from the [original Cupper](https://github.com/ThePacielloGroup/cupper) project. Here are some of its features:
{{% ticks %}}
* Responsive
* Screen reader and keyboard accessible
* TODO
* Responsive
* Shortcodes for figures, notes, and warnings, just to name a few
* Toggleable dark theme
* Toggleable table of contents
{{% /ticks %}}

View File

@ -0,0 +1,16 @@
---
date: "2014-04-09"
title: "About"
---
Hugo is the **worlds fastest framework for building websites**. It is written in Go.
It makes use of a variety of open source projects including:
* https://github.com/russross/blackfriday
* https://github.com/alecthomas/chroma
* https://github.com/muesli/smartcrop
* https://github.com/spf13/cobra
* https://github.com/spf13/viper
Learn more and contribute on [GitHub](https://github.com/gohugoio).

View File

@ -1,3 +0,0 @@
+++
title = "Coding"
+++

View File

@ -1,116 +0,0 @@
+++
title = "Code blocks"
weight = 1
+++
Markdown already supports code samples both inline (using single backticks like \`some code here\`) and in blocks. **Cupper** will syntax highlight HTML, CSS, and JavaScript if you provide the correct language in the formulation of the block.
So, this…
{{<codeBlock>}}
```html
&lt;button aria-pressed="false">toggle me&lt;/button>
```
{{</codeBlock>}}
&hellip; will result in this:
```html
<button aria-pressed="false">toggle me</button>
```
Note that the syntax highlighting uses a greyscale theme. **Cupper** is careful not to use color as part of its own design, because these colors may clash with those of the design being illustrated and discussed.
{{% note %}}
To preserve the wrapping inside code blocks, horizontal scrolling is implemented. To make sure scrolling is keyboard accessible, code blocks are focusable. An `aria-label` is provided to identify the code block to screen reader users.
{{% /note %}}
## Annotated code
**Cupper** offers the ability to highlight and annotate specific parts of your code examples using the `code` shortcode. Take an accessible dialog. You may wish to point out key attributes that make that dialog support assistive technologies:
{{<html>}}
<div ((role="dialog")) ((aria-labelledby="dialog-heading"))>
<button ((aria-label="close"))>x</button>
<h2 ((id="dialog-heading"))>Confirmation</h2>
<p>Press <strong>Okay</strong> to confirm or <strong>Cancel</strong></p>
<button>Okay</button>
<button>Cancel</button>
</div>
{{</html>}}
You mark out the highlighted areas using triple square brackets like so:
{{<codeBlock>}}
&#x7b;{&lt;code>}}
&lt;div [[[role="dialog"]]] [[[aria-labelledby="dialog-heading"]]]>
&lt;button [[[aria-label="close"]]]>x&lt;/button>
&lt;h2 [[[id="dialog-heading"]]]>Confirmation&lt;/h2>
&lt;p>Press <strong>Okay</strong> to confirm or <strong>Cancel</strong>&lt;/p>
&lt;button>Okay&lt;/button>
&lt;button>Cancel&lt;/button>
&lt;/div>
&#x7b;{&lt;/code>}}
{{</codeBlock>}}
Better still, if you include `numbered="true"`, each highlight is enumerated so you can reference it directly in the ensuing text. If you follow the shortcode directly with an ordered list, the styles match:
{{<code numbered="true">}}
<div [[[role="dialog"]]] [[[aria-labelledby="dialog-heading"]]]>
<button [[[aria-label="close"]]]>x</button>
<h2 [[[id="dialog-heading"]]]>Confirmation</h2>
<p>Press <strong>Okay</strong> to confirm or <strong>Cancel</strong></p>
<button>Okay</button>
<button>Cancel</button>
</div>
{{</code>}}
1. The dialog is only announced as a dialog if it takes the `dialog` ARIA role
2. The `aria-labelledby` relationship attribute makes the element carrying the `id` it points to its label
3. The close button uses `aria-label` to provide the text label "close", overriding the text content
4. The heading is used as the dialog's label. The `aria-labelledby` attribute points to its `id`
You just include `numbered="true"` on the opening shortcode tag:
{{<codeBlock>}}
&#x7b;{&lt;code numbered="true">}}
&lt;div [[[role="dialog"]]] [[[aria-labelledby="dialog-heading"]]]>
&lt;button [[[aria-label="close"]]]>x&lt;/button>
&lt;h2 [[[id="dialog-heading"]]]>Confirmation&lt;/h2>
&lt;p>Press <strong>Okay</strong> to confirm or <strong>Cancel</strong>&lt;/p>
&lt;button>Okay&lt;/button>
&lt;button>Cancel&lt;/button>
&lt;/div>
&#x7b;{&lt;/code>}}
1. The dialog is only announced as a dialog if it takes the `dialog` ARIA role
2. The `aria-labelledby` relationship attribute makes the element carrying the `id` it points to its label
3. The close button uses `aria-label` to provide the text label "close", overriding the text content
4. The heading is used as the dialog's label. The `aria-labelledby` attribute points to its `id`
{{</codeBlock>}}
### JavaScript example
{{<code numbered="true">}}
/* Enable scrolling by keyboard of code samples */
(function () {
var codeBlocks = document.querySelectorAll('pre, .code-annotated');
Array.prototype.forEach.call(codeBlocks, function (block) {
if (block.querySelector('code')) {
block.setAttribute([[['role', 'region']]]);
block.setAttribute([[['aria-label', 'code sample']]]);
if (block.scrollWidth > block.clientWidth) {
block.setAttribute('tabindex', '0');
}
}
});
}());
{{</code>}}
1. The `region` role announces the block as a region
2. The `aria-label` describes the kind of content to be expected in the region
{{% note %}}
As you may have noticed, using specified highlights with the `code` shortcode sacrifices syntax highlighting. If you want syntax highlighting you must use the markdown triple back-tick syntax and annotation is not available.
{{% /note %}}

View File

@ -1,17 +0,0 @@
+++
title = "Color palettes"
+++
There's no reason why your **Cupper**-powered pattern library has to be all about functionality. You can include style guide-like information such as color palettes too. The `colors` shortcode makes it easy to exhibit colors and their values together. Just supply a comma-separated list of CSS color values.
{{<codeBlock>}}
&#x7b;{% colors "#111111, #cccccc, #ffffff" %}}
{{</codeBlock>}}
The result is a one row strip showing each color supplied in order. The colors for **Cupper** are greyscale:
{{% colors "#111111, #cccccc, #ffffff" %}}
{{% note %}}
If you're wondering whether you need to put a space after the commas in the shortcode, don't worry: `"#254f7b, #579a6d, #666666"` and `"#254f7b,#579a6d,#666666"` are both accepted. Any CSS color value is acceptable, not just hex colors.
{{% /note %}}

View File

@ -1,23 +0,0 @@
+++
title = "Command line"
+++
Your pattern documentation may need to include commands for installing packages or using <abbr title="command line interface">CLI</abbr>s. **Cupper** offers the `cmd` shortcode for making code blocks look like terminal commands.
Here's how you write it:
{{<codeBlock>}}
&#x7b;{&lt;cmd>}}
npm run start
&#x7b;{&lt;/cmd>}}
{{</codeBlock>}}
And here's how it looks:
{{<cmd>}}
npm run start
{{</cmd>}}
{{% warning %}}
The `cmd` shortcode currently only supports single commands. If you want to show multiple, successive commands use separate `cmd` blocks.
{{% /warning %}}

View File

@ -1,53 +0,0 @@
+++
title = "Demo embedding"
weight = 2
+++
Sometimes just pictures of the pattern you're documenting aren't enough. Interactive patterns benefit from live demos, so that readers can test their functionality.
## CodePen
**Cupper** offers a couple of ways to do this. The first is by embedding CodePen demos into the content. The `codePen` shortcode takes just one argument: the codePen's `ID`.
{{<codeBlock>}}
&#x7b;{% codePen VpVNKW %}}
{{</codeBlock>}}
This will embed the identified codePen into the content wherever you placed the shortcode, with the result view showing by default:
{{% codePen VpVNKW %}}
{{% warning %}}
The compiled site will output an error if your `config.toml` does not include your CodePen username (in the `codePenUser` parameter). This is needed to construct the embed URL.
{{% /warning %}}
## jsBin
You can embed JS Bins just like CodePens, supplying a single `id` parameter.
{{<codeBlock>}}
&#x7b;{% jsBin juwowaq %}}
{{</codeBlock>}}
However, you can also have finer control over which panes are displayed. Use two parameters: one for the `id` and another, `show`, listing the panes you want to include.
{{<codeBlock>}}
&#x7b;{% jsBin id="juwowaq" show="css,output" %}}
{{</codeBlock>}}
The options for the `show` parameter are:
* html
* css
* js
* console
* output
(Note that, under some circumstances, the `html` pane is added whether you select it or not.)
{{% jsBin id="juwowaq" show="css,output" %}}
## Inline demos
**Cupper** also supports the ability to write inline demos directly in markdown files. See {{% pattern "Writing inline demos" %}}.

View File

@ -1,53 +0,0 @@
+++
title = "File trees"
+++
Representing folder/file structures is simple and accessible in **Cupper**. Which is just as well, because some components may need to conform to a certain folder structure.
The file tree is described using a markdown nested list structure:
{{<codeBlock>}}
&#x7b;{% fileTree %}}
* Level 1 folder
* Level 2 file
* Level 2 folder
* Level 3 file
* Level 3 folder
* Level 4 file
* Level 3 folder
* Level 4 file
* Level 4 file
* Level 3 file
* Level 2 folder
* Level 3 file
* Level 3 file
* Level 3 file
* Level 2 file
* Level 1 file
&#x7b;{% /fileTree %}}
{{</codeBlock>}}
This is drawn in the following fashion, but preserves the underlying nested list structure for assistive technologies such as screen readers:
{{% fileTree %}}
* Level 1 folder
* Level 2 file
* Level 2 folder
* Level 3 file
* Level 3 folder
* Level 4 file
* Level 3 folder
* Level 4 file
* Level 4 file
* Level 3 file
* Level 2 folder
* Level 3 file
* Level 3 file
* Level 3 file
* Level 2 file
* Level 1 file
{{% /fileTree %}}
{{% warning %}}
The only reliable way to nest unordered lists in markdown is to indent the nested item by exactly four spaces. Using tabs or less than four spaces are unreliable methods.
{{% /warning %}}

View File

@ -1,29 +0,0 @@
+++
title = "Tested using..."
+++
When you're an inclusive designer, it's pertinent to do some testing. Following specs is one thing, but you need to verify that your component works okay for users.
**Cupper** provided a `tested` shortcode that lets you show which browsers and assistive technologies you've tried your design out in. Here's an example. Note the commas and "+" signs.
{{<codeBlock>}}
&#x7b;{% tested using="Firefox + JAWS, Chrome, Safari iOS + Voiceover, Edge" %}}
{{</codeBlock>}}
This outputs:
{{% tested using="Firefox + JAWS, Chrome, Safari iOS + Voiceover, Edge" %}}
The value for the `using` attribute follows a specific format: each testing setup is separated by a comma (with a space if you like, but it's not mandatory). If you want to add an assistive technology (or any other "add on") this needs to follow a "+". This additional part can be anything, like "A VR headset I borrowed", but there are only a few browser terms available. These are case sensitive, so you need to write them as below:
* Firefox
* Chrome
* Safari
* IE
* Edge
* Opera
* Chrome Android
* Firefox Android
* Safari iOS
Obviously, this is not a comprehensive list and more may be added over time. But it covers most of the main browsers for pairing with other software — at least for testing purposes.

View File

@ -1,108 +0,0 @@
+++
title = "Writing inline demos"
weight = 3
+++
There are some issues with {{% pattern "Demo embedding" %}}, like the embeds not working offline. They also come with their own branding, which will clash with the pattern you're trying to illustrate.
**Cupper** offers another option: a special `demo` shortcode that allows you to write HTML, CSS, and JavaScript directly into the markdown file. The outputted demo is encapsulated using Shadow DOM, so you don't have to worry about broken styles and global JS.
Here's the example code for an inline demo of a toggle button:
{{<codeBlock lang="html">}}
&#x7b;{&lt;demo>}}
&lt;button aria-pressed="false">Toggle Me&lt;/button>
&lt;style>
button {
background: DarkCyan;
color: white;
border: 0;
font-size: 1.5rem;
padding: 0.5em 1em;
border-right: 5px solid #000;
border-bottom: 5px solid #000;
}
[aria-pressed="true"] {
border: 0;
border-top: 5px solid #000;
border-left: 5px solid #000;
}
&lt;/style>
&lt;script>
var toggle = demo.querySelector('[aria-pressed]');
toggle.addEventListener('click', (e) => {
let pressed = e.target.getAttribute('aria-pressed') === 'true';
e.target.setAttribute('aria-pressed', !pressed);
});
&lt;/script>
&#x7b;{&lt;/demo>}}
{{</codeBlock>}}
Note the `demo.querySelector` on line `21`. **Cupper** automatically provides `demo`, representing the root node of the demo. It's like the `document` keyword but for a demo's subtree.
Here's a live demo _of_ the demo:
{{<demo>}}
<button aria-pressed="false">Toggle Me</button>
<style>
button {
background: DarkCyan;
color: white;
border: 0;
border-radius: 0.25em;
font-size: 1.5rem;
padding: 0.5em 1em;
border-right: 5px solid #000;
border-bottom: 5px solid #000;
}
[aria-pressed="true"] {
border: 0;
border-top: 5px solid #000;
border-left: 5px solid #000;
}
</style>
<script>
var toggle = demo.querySelector('[aria-pressed]');
toggle.addEventListener('click', function () {
var pressed = this.getAttribute('aria-pressed') === 'true';
this.setAttribute('aria-pressed', !pressed);
});
</script>
{{</demo>}}
## Styling the container
Sometimes your component will be expected to appear in a context where the parent element has a background color and possibly other styles. You can add style to your demo block's container element using the `style` attribute. It works just like standard inline styling.
{{<codeBlock lang="html">}}
&#x7b;{&lt;demo style="background-color: pink; padding: 1rem;">}}
&lt;!-- demo code here -->
&#x7b;{&lt;/demo>}}
{{</codeBlock>}}
## "Launch"
The "Launch" button takes the demo code and pushes it to a new browser tab. This serves two purposes:
* It provides a fallback for browsers that do not support Shadow DOM encapsulation (a warning message will replace the inline demo).
* It creates an isolated test case for the demo, allowing you to run browser extensions and bookmarklets on the the demo code and _just_ the demo code.
{{% note %}}
The "Launch" button is positioned over the styleable demo container. Bear this is mind when styling the container (see the previous section).
{{% /note %}}
## Captioned demos
It's possible to give your demo a caption using an accessible `<figure>` and `<figcaption>` structure. All _you_ need to do is supply a `caption` attribute. For example:
{{<codeBlock lang="html">}}
&#x7b;{&lt;demo caption="A basic button element">}}
&lt;!-- demo code here -->
&#x7b;{&lt;/demo>}}
{{</codeBlock>}}
Along with the standard `figure` shortcodes (described in {{% pattern "Including images" %}}), demo figures are numbered automatically according to their order in the page. You can use markdown syntax in the caption text value.

View File

@ -1,54 +0,0 @@
+++
title = "Installation"
weight = 1
+++
**Cupper** is built using the static site engine, [Hugo](https://gohugo.io/), and NPM. The codebase is available to download on Github. Let's get everything installed step-by-step.
## Install Hugo
First you need to install Hugo globally.
### OSX users
If you are a Mac user and have [Homebrew](https://brew.sh/) on your system, installing Hugo is simple:
{{<cmd>}}brew install hugo{{</cmd>}}
Alternatively, you can manually [install Hugo from a package](https://github.com/gohugoio/hugo/releases). You can verify the installation was successful by typing:
{{<cmd>}}hugo version{{</cmd>}}
### Windows users
Installing on Windows is a little more involved than on OSX. The authors of Hugo provide [a guide](https://gohugo.io/tutorials/installing-on-windows/) with instructions for technical and less technical users.
It's also best you install a Windows Subsystem for running Linux, and therefore [bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) (**Cupper** incorporates some bash commands in its scripts). [Microsoft offer a complete guide](https://msdn.microsoft.com/en-gb/commandline/wsl/install_guide).
## Install Node & NPM
It is likely you already have Node and NPM installed on your system. If so, you can skip this step. Otherwise, [refer to NPM's own guide](https://docs.npmjs.com/getting-started/installing-node), which includes a video tutorial.
## Get the files
**Cupper** is hosted on Github. To start using it, you'll need to get the files from there. If you are comfortable with the command line, just fork the [github.com/ThePacielloGroup/cupper](https://github.com/ThePacielloGroup/cupper) repository, then do a `git clone` to your local system. Replace `[your username]` in the following:
{{<cmd>}}git clone https://github.com/[your username]/cupper.git{{</cmd>}}
If the command line is not your thing, use Github's web interface to fork [github.com/ThePacielloGroup/cupper](https://github.com/ThePacielloGroup/cupper) and choose **Open in Desktop** from **Clone or download** (see figure 1, below).
{{% figure caption="The Github web interface" %}}
![The open in desktop option, revealed when clicking clone or download](/images/open_in_desktop.png)
{{% /figure %}}
{{% note %}}
If you do not have a version of the Github desktop client installed, follow the prompts after clicking **Open in Desktop**.
{{% /note %}}
While you're in the Github interface, you might as well set up the publishing source for the live site. Choose the Master branch/docs option under **Settings → Github Pages → Source**. See {{% pattern "Serving" %}} for more details.
Once you have your local copy of the files, move to the root of that folder and in your terminal run an npm installation:
{{<cmd>}}npm install{{</cmd>}}
Now it's time to consult the {{% pattern "Setup" %}} pattern.

View File

@ -1,4 +0,0 @@
+++
title = "Media"
weight = 2
+++

View File

@ -1,50 +0,0 @@
+++
title = "Including images"
+++
From time to time, you'll be wanting to include images illustrating the documented pattern in hand. Images live in the static folder, which is a sibling of the `/content` folder you'll be mostly working in.
{{% fileTree %}}
* content
* static
* images
* logo.png
* menu-button.gif
{{% /fileTree %}}
{{% note %}}
When you first make a copy of **Cupper**, **Cupper's** own logo will be included. You should replace this with your own company or project logo.
{{% /note %}}
The path to the `/images` folder should begin with a forward slash, so include that when referencing images in your markdown.
```
![Global Megacorp Ltd](/images/logo.png)
```
## Figures
Sometimes you will want to include a caption with your illustration. This is what the `<figure>` and `<figcaption>` elements are for. However, **Cupper** doesn't ask you to code all that manually. A special shortcode is provided, which takes a `caption` parameter. Note that the image markdown is provided between the opening and closing shortcode tags, and that you can use markdown syntax in the `caption` value.
{{<codeBlock>}}
&#x7b;{% figure caption="A design system that uses a bad code example as a **single source of truth** only serves to proliferate bad code." %}}
![Diagram of a design pattern represented by a turd emoji begetting three bad implementations](/images/bad_design_system.png)
&#x7b;{% /figure %}}
{{</codeBlock>}}
This will output the following. Note the automatically incremented **Figure** number.
{{% figure caption="A design system that uses a bad code example as a **single source of truth** only serves to proliferate bad code." %}}
![Diagram of a design pattern represented by a turd emoji begetting three bad implementations](/images/bad_design_system.png)
{{% /figure %}}
The generated markup includes special provisions for assistive technology support:
```html
<figure role="group" aria-describedby="caption-5fbafefe946c724e7a5d3d2d447a8684">
<p><img src="http://localhost:1313/images/bad_design_system.png" alt="Diagram of a design pattern represented by a turd emoji begetting three bad implementations"></p>
<figcaption id="caption-5fbafefe946c724e7a5d3d2d447a8684">
A design system that uses a bad code example as a <strong>single source of truth</strong> only serves to proliferate bad code.
</figcaption>
</figure>
```

View File

@ -1,9 +0,0 @@
+++
title = "Including videos"
+++
**Cupper** has a lot of its own shortcodes, but you can still use Hugo's [built in shortcodes](https://gohugo.io/extras/shortcodes#built-in-shortcodes). These include a simple shortcode for including YouTube videos in your content. The shortcode takes just one parameter — the video's `id`.
{{<codeBlock>}}
&#x7b;{&lt;youtube w7Ft2ymGmfc>}}
{{</codeBlock>}}

View File

@ -1,14 +0,0 @@
+++
title = "Printing"
weight = 4
+++
**Cupper**'s output site includes a one-page {{% pattern "Print version" %}} of the generated library, available at `/print-version`. So, if your library base URL is `https://yourName.github.io/your-library`, you can print the whole library — to PDF if wanted — from the following address:
```
https://yourName.github.io/your-library/print-version
```
{{% note %}}
Print styles are also provided for individual pattern pages so, if you wanted to print off a single pattern document, you can!
{{% /note %}}

View File

@ -1,34 +0,0 @@
+++
title = "Serving"
weight = 3
+++
## Serving locally
While you're creating content for your project, you'll probably want to see what the finished product looks like. Fortunately, **Cupper** is easy to serve locally using the `serve` command:
{{<cmd>}}npm run serve{{</cmd>}}
This will serve your working project from `localhost:1313`. Whenever you make changes to your files, the site will automatically rebuild. No need to refresh the web page!
## Publishing on Github Pages
**Cupper** creates a `/docs` folder containing the latest version of your site whenever you do an `npm run build` or a `git commit`. So long as you forked the **Cupper** repository when making your own version (see {{% pattern "Setup" %}}), whenever you push to master, you will also be updating the site found at your Github Pages URL.
This URL will be in the following format:
```
[your user name].github.io/[your library repo name]
```
You'll also need to add this value to your `config.toml` file as the `baseURL`. For **Cupper**'s own documentation it looks like the following. Just overwrite it.
```
baseURL = "https://thepaciellogroup.github.io/cupper/"
```
### Set the publishing source
You will find the `docs` folder is not automatically setup as the publishing source, even when forking the repo. In which case, you must set it under **Settings → Github Pages → Source** in the web interface.
![The publishing source dropdown menu on Github](/images/serve_from_docs.png)

View File

@ -1,73 +0,0 @@
+++
title = "Setup"
weight = 2
+++
By now, you should have followed the {{% pattern "Installation" %}} instructions. You should have Hugo and Node installed, and a local copy of a forked version of **Cupper**. You should also have run `npm install` in the root of that codebase.
## "Cleaning" the content folder
Before you can start writing documentation, there are a few things still to do in order to get set up. At the moment, your version of **Cupper** is a facsimile of the original, containing all the content you're reading right now. We want to delete that content and replace it with some starter content. There's a simple `clean` command for this.
{{% warning %}}
If you are contributing to an existing **Cupper** library, do not run the following command. It will delete all of the patterns in that library. The `clean` command is just for libraries that you are starting from scratch.
{{% /warning %}}
{{<cmd>}}
npm run clean
{{</cmd>}}
This will leave your `content` folder with just an `_index.md` file and a `patterns` folder containing a single demonstration pattern file. Individual content pages in **Cupper** are referred to as "patterns" — think pattern libraries). Find out more about these in {{% pattern "Project structure" %}}.
## The config file
You'll also want to name your project and configure one or two other things in the `config.toml` file that's found at the root of your project. Here's how that file looks:
{{<codeBlock lang="html" numbered="true">}}
languageCode = "en-us"
title = "Cupper"
baseURL = "https://thepaciellogroup.github.io/cupper/"
theme = "cupper"
[params]
description = "Documentation for the **Cupper** documentation builder. This documentation is constructed using the builder itself."
codePenUser = "Heydon"
{{</codeBlock>}}
* **title** — This is the project's name, like "Megacorp 5000 Pattern Library" or "Assplosion.js Documentation". For **Cupper's** own version of **Cupper**, the `title` is simply _Cupper_ :-)
* **baseURL** — This is the root of the live site. Typically you will publish the site to Github Pages, so this should be the base URL for your Github Pages site.
* **theme** — This is the theme the library is using. Don't change this from "cupper".
* **description** — This is a short description of your documentation project and comes under the logo. You can include markdown syntax here, like _&#x002a;&#x002a;Cupper&#x002a;&#x002a;_ in the above example for making the name of the library bold.
* **codePenUser** — If you want to embed codePens in your pattern files, you need to supply a codePen username here.
## The Web App Manifest
**Cupper** projects work as progressive web applications, meaning users can save them to their home screen and read them offline. The web app manifest, found at the root of the `static` folder, defines names and icons for the app. You'll probably want to open `/static/manifest.json` and personalize the `name` and `short_name` values.
```
{
"name": "Cupper Documentation Builder",
"short_name": "Cupper Docs",
"icons": [
{...
```
{{% figure caption="Cupper's Docs, with `short_name` displayed, available from the homescreen of a Samsung/Android phone." %}}
![Teacup Cupper app icon with Cupper Docs written underneath](/images/samsung_homescreen.jpg)
{{% /figure %}}
{{% note %}}
The `short_name` value refers to the text that appears under the icon on your homescreen. As the name suggests, it should be as short as possible to fit well (12 characters or fewer is ideal).
{{% /note %}}
## Including a logo
In the `images/static` folder, you'll find a `logo.svg` file. Replace this file with your own company or project logo, under the same file name. Currently, only SVG is supported this easily because SVG is the superior format for logos. However, if you must use a different format, you can open up the `themes/cupper/layouts/_default/baseof.html` file and edit the image reference:
```html
<a class="logo" href="/" aria-label="{{ .Site.Title }} pattern library home page">
<img src="{{ "images/logo.svg" | absURL }}" alt="">
</a>
```
Now that your logo is in place, everything should be ready. Where next? You can learn about {{% pattern "Project structure" %}} to help you get writing, or find out how to serve the site locally and on Github Pages in {{% pattern "Serving" %}}.

View File

@ -1,38 +0,0 @@
+++
title = "Updating Cupper"
weight = 5
+++
The core of **Cupper's** functionality is in its Hugo theme, also called **Cupper**. This is found in the theme folder.
{{% fileTree %}}
* content
* docs
* lib
* snippets
* static
* themes
* cupper
{{% /fileTree %}}
Do not "hack the core". If you have any issues with **Cupper**, please report them to [the **Cupper** Github repository](https://github.com/ThePacielloGroup/cupper/issues) and they will be dealt with ASAP.
Cupper is undergoing constant development, so keep an eye out for new releases. To update to a new version of **Cupper**, simply run the `update` command from inside your local project folder.
{{<cmd>}}
npm run update
{{</cmd>}}
This will save a timestamped backup of the current version, and download the latest version. Your theme folder will now look something like the following.
{{% fileTree %}}
* themes
* cupper
* cupper-old-1503389765972
{{% /fileTree %}}
If you experience breaking changes and are having trouble fixing them, you can rename the old folder and revert to using it. In the meantime, you can [submit an issue](https://github.com/ThePacielloGroup/cupper/issues) with the "help" tag describing your problem.
{{% warning %}}
The described update process relies on SVN because Github does not support downloading individual repository folders. If you have a Mac, SVN should be installed already. If not, or if you are on Windows, you can either install SVN or download the latest [**Cupper** theme folder](https://github.com/ThePacielloGroup/cupper/tree/master/themes/cupper) manually, using the Github web interface.
{{% /warning %}}

View File

@ -1,4 +0,0 @@
+++
title = "Writing"
weight = 1
+++

View File

@ -1,48 +0,0 @@
+++
title = "Expandable sections"
weight = 6
+++
In some cases, where there is a lot of content, it's helpful to collapse certain sections. That way, readers get an overview of what's in the content and can choose where to focus in. **Cupper** provides a shortcode method for creating expandable sections which generates accessible markup using `aria-expanded`.
The `expandable` shortcode takes three parameters:
* **label** — This is the label for the the section heading.
* **level** — This is the heading level (e.g. `level="2"` for an `<h2>`) that will contain the label. If you omit a level parameter, no heading is used; it's just a button.
* **open** — Include this and give it a value of "true" or "yes" to make the section expanded on page load.
Here's what the code might look like for a simple expandable section containing markdown:
{{<codeBlock>}}
&#x7b;{% expandable label="A section of dummy text" level="2" %}}
Here is some markdown including [a link](https://twitter.com/heydonworks). Donec erat est, feugiat a est sed, aliquet pharetra ipsum. Vivamus in arcu leo. Praesent feugiat, purus a molestie ultrices, libero massa iaculis ante, sit amet accumsan leo eros vel ligula.
&#x7b;{% /expandable %}}
{{</codeBlock>}}
Let's look at what that outputs:
{{% expandable label="A section of dummy text" level="2" %}}
Here is some markdown including [a link](https://twitter.com/heydonworks). Donec erat est, feugiat a est sed, aliquet pharetra ipsum. Vivamus in arcu leo. Praesent feugiat, purus a molestie ultrices, libero massa iaculis ante, sit amet accumsan leo eros vel ligula.
{{% /expandable %}}
Successive collapsible sections fit snugly together. The second of the following two has `open="true"`.
{{% expandable label="A section of dummy text" level="2" %}}
Mauris eget elit ut neque venenatis placerat id nec libero. Nunc accumsan cursus elit nec iaculis. Proin id rutrum magna, a aliquet sem. Sed et tortor id sem eleifend porta vitae eget elit. Cras sodales porta malesuada. Suspendisse at odio ac tortor.
{{% /expandable %}}
{{% expandable label="Another dummy section" level="2" open="true" %}}
Ut vulputate enim ut lorem iaculis, vel faucibus metus iaculis. Aliquam erat volutpat. Aliquam luctus orci vel consectetur dignissim. Nullam et efficitur lorem, et ornare est. Sed tristique porttitor justo, quis malesuada velit. Nullam et elit finibus, sollicitudin velit placerat, ultricies dui.
{{% /expandable %}}
Unfortunately, it is not currently possible to include shortcodes inside other shortcodes, using the "`%`" notation (which is designated for markdown content). If you use the angle brackets notation (illustrated below) it is possible, but markdown will no longer be permitted. You will have to code HTML inside such a section manually.
{{<codeBlock>}}
&#x7b;{&lt;expandable label="A section of dummy text" level="2">}}
&lt;p>Here is a pattern reference shortcode: &#x7b;{% pattern "Writing inline demos" %}}.&lt;/p>
&#x7b;{&lt;/expandable>}}
{{</codeBlock>}}
{{% note %}}
When you go to print a pattern from your library, some print styles take care of collapsible sections, making them appear expanded and like any other section.
{{% /note %}}

View File

@ -1,52 +0,0 @@
+++
title = "Markdown & metadata"
weight = 3
tags = ['metadata', 'markdown']
+++
In **Cupper** everything is documented using markdown, as a "pattern". To create a new pattern file, just add a file with the `.md` extension to the `content/patterns` folder. It's recommended you use "kebab case" to name the file (words separated by hyphens). For example, a pattern with the title "Menu button" should probably have the filename `menu-button`. Then you get a nice clean URL: `username.github.io/your-library/patterns/menu-button`.
If you're not familiar with writing markdown, there are a number of tutorials available. One of the best is [Mastering Markdown](https://guides.github.com/features/mastering-markdown/) offered by Github. There's also a [nice cheatsheet here](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet).
## The metadata
Like many static site generators, Hugo lets you add metadata to its markdown files. Hugo's brand of metadata is called TOML (although YAML is also accepted). The only thing you _have_ to put in the TOML is a `title` — like this:
```
+++
title = "Menu button"
+++
```
{{% note %}}
The title automatically becomes the page's main `<h1>` heading. The highest heading level you should use in the body of your markdown file is therefore `<h2>`.
{{% /note %}}
### Tags
If you like, you can also tag the pattern so that it turns up in lists of similar content. You add tags in an array format. Note that all the TOML data is found at the top of the markdown file, between the `+++` lines.
```
+++
title = "Menu button"
tags = ["interactive", "popup", "javascript"]
+++
```
This will create links to pages listing content tagged with the same terms using the URL schema `/tag/[tag name]`. Some example tags links are provided for this page, which you can see listed under the main heading.
### Weight
By default, patterns are listed alphabetically in the navigation. However, sometimes you might like to change the order around. This is possible by adding a `weight` parameter. To make my menu button pattern appear at the top of its subsection, I would give it a `weight` of `1`:
```
+++
title = "Menu button"
tags = ["interactive", "popup", "javascript"]
weight = 1
+++
```
{{% warning %}}
The `weight` parameter should be an integer, not a string, so don't use scare quotes around the value!
{{% /warning %}}

View File

@ -1,37 +0,0 @@
+++
title = "Notes & warnings"
+++
**Cupper** acknowledges that simple markdown is limiting when it comes to writing compelling documentation, so it provides a number of "shortcodes". Shortcodes offer a simple syntax for including rich content. For example, **Cupper** provides shortcodes for including notes and warnings.
## Notes
You may wish to pick out some content in your pattern's documentation as a note — an aside to the main thrust of the pattern's description. This is possible using the following syntax:
{{<codeBlock>}}
&#x7b;{% note %}}
This is a note! It's something the reader may like to know about but is supplementary to the main content. Use notes when something may be interesting but not critical.
&#x7b;{% /note %}}
{{</codeBlock>}}
Notes render like this:
{{% note %}}
This is a note! It's something the reader may like to know about but is supplementary to the main content. Use notes when something may be interesting but not critical.
{{% /note %}}
## Warnings
Warnings are like notes, but with more urgency.
{{<codeBlock>}}
&#x7b;{% warning %}}
This is a warning! It's about something the reader should be careful to do or to avoid doing. Use warnings when something could go wrong.
&#x7b;{% /warning %}}
{{</codeBlock>}}
Warnings render like this:
{{% warning %}}
This is a warning! It's about something the reader should be careful to do or to avoid doing. Use warnings when something could go wrong.
{{% /warning %}}

View File

@ -1,52 +0,0 @@
+++
title = "Project structure"
weight = 1
+++
Before you can set about making documentation, you need to know where everything goes. The simplest folder structure looks like this:
{{% fileTree %}}
* content
* \_index.md
* print-version.md
* patterns
* name-of-my-pattern.md
* name-of-my-other-pattern.md
{{% /fileTree %}}
* **/content** - This is where all of your content lives. You won't need to visit any other folders very frequently.
* **_index.md** — This is the content file for your home page.
* **print-version.md** — This is a placeholder for the single-page / print-friendly version of you library. Leave this file as it is.
* **/patterns** — This is the folder where individual content files are kept. **Cupper** refers to each individual documentation file/page as a "pattern".
## Subsections
You may have noticed that this site's navigation is divided partly into subsections, with labels like "Writing". **Cupper** (or, rather, Hugo) allows you to create such subsections by simply nesting folders under the `/patterns` folder. In the following example, I have a subsection about different types of "popup" pattern.
{{% fileTree %}}
* content
* \_index.md
* patterns
* name-of-my-pattern.md
* name-of-my-other-pattern.md
* popups
* \_index.md
* popup-menu.md
* tooltips.md
{{% /fileTree %}}
Subfolders like `/popups` must each have an `_index.md` file. This file doesn't need any content except the TOML metadata defining the title (name) of that subsection:
```
+++
title = "Popup windows"
+++
```
This title is what labels the subsection in the navigation, *not* the folder name (`/popups`, in this case). For each subfolder you create, you must also create one of these `_index.md` files. The `/patterns` folder itself does not need one, however.
{{% note %}}
**Cupper** does not currently support _sub_-subsections. You can only create child folders under `/patterns`.
{{% /note %}}
Now that you know where to put everything, it's time to talk about how to actually write individual patterns. Don't worry, it's pretty straightforward. Turn to {{% pattern "Markdown & metadata" %}}.

View File

@ -1,63 +0,0 @@
+++
title = "References"
+++
## Cross-references
**Cupper** identifies the main content files in your documentation as _patterns_, and they're kept in the **content/ patterns** folder. It's easy to cross-reference patterns using the `pattern` shortcode. For example, I can reference the {{% pattern "Notes & warnings" %}} pattern. Here's what the markdown looks like, including the shortcode:
{{<codeBlock>}}
I can reference the &#x7b;{% pattern "Notes & warnings" %}} pattern here.
{{</codeBlock>}}
This saves you having to worry about pathing and decorates the generated link with a bookmark icon, identifying the link as a pattern reference visually.
{{% note %}}
The title argument you supply to the shortcode must be exactly the same as the referenced pattern's `title` metadata value and is case sensitive.
{{% /note %}}
## WCAG References
[WCAG 2.0](https://www.w3.org/TR/WCAG/) is the _de facto_ standard for accessible interfaces. When writing about inclusive interfaces, sometimes you'll want to refer to WCAG to highlight which success criteria the pattern meets.
Instead of having to copy and paste content and links to WCAG, **Cupper** provides a shortcode mechanism that lets you simply list the success criteria by number:
{{<codeBlock>}}
&#x7b;{% wcag include="1.2.1, 1.3.1, 4.1.2" %}}
{{</codeBlock>}}
This generates a list of references that includes the names of each criterion and links to them directly. Like this:
{{% wcag include="2.1.1, 4.1.2" %}}
{{% note %}}
You don't have to leave spaces after the comma separators. They are optional.
{{% /note %}}
### Full descriptions
Sometimes, you'll want to include the full descriptions of the success criteria inline. This is possible by setting `descriptions` to `true`:
{{<codeBlock>}}
&#x7b;{% wcag include="1.3.1, 4.1.2" descriptions="true" %}}
{{</codeBlock>}}
Here's the more verbose output:
{{% wcag include="2.1.1, 4.1.2" descriptions="true" %}}
{{% note %}}
Both omitting the `descriptions` attribute and including it with a "false" value will omit descriptions. If it is included it _must_ have a value. A boolean attribute will break the output.
{{% /note %}}
## Inclusive Design Principle references
Some inclusive design concepts are not reducible to success or fail criteria. This is why The Paciello Group wrote the [Inclusive Design Principles](http://inclusivedesignprinciples.org/). These can be listed by name.
{{<codeBlock>}}
&#x7b;{% principles include="Add value, Be consistent" descriptions="true" %}}
{{</codeBlock>}}
Here's the output with `descriptions="true"`:
{{% principles include="Add value,Be consistent" descriptions="true" %}}

View File

@ -1,19 +0,0 @@
+++
title = "Snippets"
+++
A lot of the time, your larger documentation patterns will share some common techniques and utilities. For this reason, **Cupper** lets you save snippets of markdown in a **snippets** folder, alongside the main content folder.
The example `visually-hidden.md` snippet describes the CSS needed to create content that is visually hidden but still available to screen readers. Since this is a technique/utility you are likely to use often, it's nice to be able to just drop a snippet into your markdown content. The `snippet` shortcode lets you do exactly that:
{{<codeBlock>}}
&#x7b;{% snippet file="visually-hidden.md" %}}
{{</codeBlock>}}
{{% note %}}
To make your snippets truly reusable, try to write them in such a way that they make sense independent of surrounding text, a little bit like this note does.
{{% /note %}}
## Visually hidden snippet
{{/% snippet file="visually-hidden.md" %/}}

View File

@ -1,34 +0,0 @@
+++
title = "Tables of contents"
+++
Pattern pages in **Cupper** that have two or more subheadings (`<h2>`s) automatically get a **table of contents**: a list of links to the main subsections for the page. This feature is made accessible as a navigation region with the "Table of contents" label and uses an ordered list. The table of contents markup for the {{% pattern "Setup" %}} page looks something like this:
```html
<nav class="toc" aria-labelledby="toc-heading">
<h2 id="toc-heading">Table of contents</h2>
<ol>
<li>
<a href="#cleaning-the-content-folder">“Cleaning” the content folder</a>
</li>
<li>
<a href="#the-setup-command">The setup command</a>
</li>
<li>
<a href="#the-config-file">The config file</a>
</li>
<li>
<a href="#including-a-logo">Including a logo</a>
</li>
</ol>
</nav>
```
Tables of content are a neat way to break down the content of the page and give users a navigable overview. However, they may not be to your taste. Never fear, you can turn tables of content off by adding `toc = false` to the TOML metadata for your pattern:
```
+++
title = "My page with a few headings"
toc = false
+++
```

View File

@ -0,0 +1,3 @@
---
title: Blog
---

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,332 @@
---
date: "2014-04-02"
tags: ["go", "templates", "hugo"]
title: "(Hu)go Template Primer"
---
Hugo uses the excellent [Go][] [html/template][gohtmltemplate] library for
its template engine. It is an extremely lightweight engine that provides a very
small amount of logic. In our experience that it is just the right amount of
logic to be able to create a good static website. If you have used other
template systems from different languages or frameworks you will find a lot of
similarities in Go templates.
This document is a brief primer on using Go templates. The [Go docs][gohtmltemplate]
provide more details.
## Introduction to Go Templates
Go templates provide an extremely simple template language. It adheres to the
belief that only the most basic of logic belongs in the template or view layer.
One consequence of this simplicity is that Go templates parse very quickly.
A unique characteristic of Go templates is they are content aware. Variables and
content will be sanitized depending on the context of where they are used. More
details can be found in the [Go docs][gohtmltemplate].
## Basic Syntax
Golang templates are HTML files with the addition of variables and
functions.
**Go variables and functions are accessible within {{ }}**
Accessing a predefined variable "foo":
{{ foo }}
**Parameters are separated using spaces**
Calling the add function with input of 1, 2:
{{ add 1 2 }}
**Methods and fields are accessed via dot notation**
Accessing the Page Parameter "bar"
{{ .Params.bar }}
**Parentheses can be used to group items together**
{{ if or (isset .Params "alt") (isset .Params "caption") }} Caption {{ end }}
## Variables
Each Go template has a struct (object) made available to it. In hugo each
template is passed either a page or a node struct depending on which type of
page you are rendering. More details are available on the
[variables](/layout/variables) page.
A variable is accessed by referencing the variable name.
<title>{{ .Title }}</title>
Variables can also be defined and referenced.
{{ $address := "123 Main St."}}
{{ $address }}
## Functions
Go template ship with a few functions which provide basic functionality. The Go
template system also provides a mechanism for applications to extend the
available functions with their own. [Hugo template
functions](/layout/functions) provide some additional functionality we believe
are useful for building websites. Functions are called by using their name
followed by the required parameters separated by spaces. Template
functions cannot be added without recompiling hugo.
**Example:**
{{ add 1 2 }}
## Includes
When including another template you will pass to it the data it will be
able to access. To pass along the current context please remember to
include a trailing dot. The templates location will always be starting at
the /layout/ directory within Hugo.
**Example:**
{{ template "chrome/header.html" . }}
## Logic
Go templates provide the most basic iteration and conditional logic.
### Iteration
Just like in Go, the Go templates make heavy use of range to iterate over
a map, array or slice. The following are different examples of how to use
range.
**Example 1: Using Context**
{{ range array }}
{{ . }}
{{ end }}
**Example 2: Declaring value variable name**
{{range $element := array}}
{{ $element }}
{{ end }}
**Example 2: Declaring key and value variable name**
{{range $index, $element := array}}
{{ $index }}
{{ $element }}
{{ end }}
### Conditionals
If, else, with, or, & and provide the framework for handling conditional
logic in Go Templates. Like range, each statement is closed with `end`.
Go Templates treat the following values as false:
* false
* 0
* any array, slice, map, or string of length zero
**Example 1: If**
{{ if isset .Params "title" }}<h4>{{ index .Params "title" }}</h4>{{ end }}
**Example 2: If -> Else**
{{ if isset .Params "alt" }}
{{ index .Params "alt" }}
{{else}}
{{ index .Params "caption" }}
{{ end }}
**Example 3: And & Or**
{{ if and (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr")}}
**Example 4: With**
An alternative way of writing "if" and then referencing the same value
is to use "with" instead. With rebinds the context `.` within its scope,
and skips the block if the variable is absent.
The first example above could be simplified as:
{{ with .Params.title }}<h4>{{ . }}</h4>{{ end }}
**Example 5: If -> Else If**
{{ if isset .Params "alt" }}
{{ index .Params "alt" }}
{{ else if isset .Params "caption" }}
{{ index .Params "caption" }}
{{ end }}
## Pipes
One of the most powerful components of Go templates is the ability to
stack actions one after another. This is done by using pipes. Borrowed
from unix pipes, the concept is simple, each pipeline's output becomes the
input of the following pipe.
Because of the very simple syntax of Go templates, the pipe is essential
to being able to chain together function calls. One limitation of the
pipes is that they only can work with a single value and that value
becomes the last parameter of the next pipeline.
A few simple examples should help convey how to use the pipe.
**Example 1 :**
{{ if eq 1 1 }} Same {{ end }}
is the same as
{{ eq 1 1 | if }} Same {{ end }}
It does look odd to place the if at the end, but it does provide a good
illustration of how to use the pipes.
**Example 2 :**
{{ index .Params "disqus_url" | html }}
Access the page parameter called "disqus_url" and escape the HTML.
**Example 3 :**
{{ if or (or (isset .Params "title") (isset .Params "caption")) (isset .Params "attr")}}
Stuff Here
{{ end }}
Could be rewritten as
{{ isset .Params "caption" | or isset .Params "title" | or isset .Params "attr" | if }}
Stuff Here
{{ end }}
## Context (aka. the dot)
The most easily overlooked concept to understand about Go templates is that {{ . }}
always refers to the current context. In the top level of your template this
will be the data set made available to it. Inside of a iteration it will have
the value of the current item. When inside of a loop the context has changed. .
will no longer refer to the data available to the entire page. If you need to
access this from within the loop you will likely want to set it to a variable
instead of depending on the context.
**Example:**
{{ $title := .Site.Title }}
{{ range .Params.tags }}
<li> <a href="{{ $baseurl }}/tags/{{ . | urlize }}">{{ . }}</a> - {{ $title }} </li>
{{ end }}
Notice how once we have entered the loop the value of {{ . }} has changed. We
have defined a variable outside of the loop so we have access to it from within
the loop.
# Hugo Parameters
Hugo provides the option of passing values to the template language
through the site configuration (for sitewide values), or through the meta
data of each specific piece of content. You can define any values of any
type (supported by your front matter/config format) and use them however
you want to inside of your templates.
## Using Content (page) Parameters
In each piece of content you can provide variables to be used by the
templates. This happens in the [front matter](/content/front-matter).
An example of this is used in this documentation site. Most of the pages
benefit from having the table of contents provided. Sometimes the TOC just
doesn't make a lot of sense. We've defined a variable in our front matter
of some pages to turn off the TOC from being displayed.
Here is the example front matter:
```
---
title: "Permalinks"
date: "2013-11-18"
aliases:
- "/doc/permalinks/"
groups: ["extras"]
groups_weight: 30
notoc: true
---
```
Here is the corresponding code inside of the template:
{{ if not .Params.notoc }}
<div id="toc" class="well col-md-4 col-sm-6">
{{ .TableOfContents }}
</div>
{{ end }}
## Using Site (config) Parameters
In your top-level configuration file (eg, `config.yaml`) you can define site
parameters, which are values which will be available to you in chrome.
For instance, you might declare:
```yaml
params:
CopyrightHTML: "Copyright &#xA9; 2013 John Doe. All Rights Reserved."
TwitterUser: "spf13"
SidebarRecentLimit: 5
```
Within a footer layout, you might then declare a `<footer>` which is only
provided if the `CopyrightHTML` parameter is provided, and if it is given,
you would declare it to be HTML-safe, so that the HTML entity is not escaped
again. This would let you easily update just your top-level config file each
January 1st, instead of hunting through your templates.
```
{{if .Site.Params.CopyrightHTML}}<footer>
<div class="text-center">{{.Site.Params.CopyrightHTML | safeHtml}}</div>
</footer>{{end}}
```
An alternative way of writing the "if" and then referencing the same value
is to use "with" instead. With rebinds the context `.` within its scope,
and skips the block if the variable is absent:
```
{{with .Site.Params.TwitterUser}}<span class="twitter">
<a href="https://twitter.com/{{.}}" rel="author">
<img src="/images/twitter.png" width="48" height="48" title="Twitter: {{.}}"
alt="Twitter"></a>
</span>{{end}}
```
Finally, if you want to pull "magic constants" out of your layouts, you can do
so, such as in this example:
```
<nav class="recent">
<h1>Recent Posts</h1>
<ul>{{range first .Site.Params.SidebarRecentLimit .Site.Recent}}
<li><a href="{{.RelPermalink}}">{{.Title}}</a></li>
{{end}}</ul>
</nav>
```
[go]: https://golang.org/
[gohtmltemplate]: https://golang.org/pkg/html/template/

View File

@ -0,0 +1,78 @@
---
date: "2014-04-02"
tags: ["hugo", "git", "fun"]
title: "Getting Started with Hugo"
---
## Step 1. Install Hugo
Go to [Hugo releases](https://github.com/spf13/hugo/releases) and download the
appropriate version for your OS and architecture.
Save it somewhere specific as we will be using it in the next step.
More complete instructions are available at [Install Hugo](https://gohugo.io/getting-started/installing/)
## Step 2. Build the Docs
Hugo has its own example site which happens to also be the documentation site
you are reading right now.
Follow the following steps:
1. Clone the [Hugo repository](http://github.com/spf13/hugo)
2. Go into the repo
3. Run hugo in server mode and build the docs
4. Open your browser to http://localhost:1313
Corresponding pseudo commands:
git clone https://github.com/spf13/hugo
cd hugo
/path/to/where/you/installed/hugo server --source=./docs
> 29 pages created
> 0 tags index created
> in 27 ms
> Web Server is available at http://localhost:1313
> Press ctrl+c to stop
Once you've gotten here, follow along the rest of this page on your local build.
## Step 3. Change the docs site
Stop the Hugo process by hitting Ctrl+C.
Now we are going to run hugo again, but this time with hugo in watch mode.
/path/to/hugo/from/step/1/hugo server --source=./docs --watch
> 29 pages created
> 0 tags index created
> in 27 ms
> Web Server is available at http://localhost:1313
> Watching for changes in /Users/spf13/Code/hugo/docs/content
> Press ctrl+c to stop
Open your [favorite editor](http://vim.spf13.com) and change one of the source
content pages. How about changing this very file to *fix the typo*. How about changing this very file to *fix the typo*.
Content files are found in `docs/content/`. Unless otherwise specified, files
are located at the same relative location as the url, in our case
`docs/content/overview/quickstart.md`.
Change and save this file.. Notice what happened in your terminal.
> Change detected, rebuilding site
> 29 pages created
> 0 tags index created
> in 26 ms
Refresh the browser and observe that the typo is now fixed.
Notice how quick that was. Try to refresh the site before it's finished building. I double dare you.
Having nearly instant feedback enables you to have your creativity flow without waiting for long builds.
## Step 4. Have fun
The best way to learn something is to play with it.

View File

@ -0,0 +1,159 @@
---
date: "2014-03-10"
draft: false
lastmod: "2014-03-10"
publishdate: "2014-03-10"
tags:
- hugo
- jekyll
- migration
- git
- templates
title: Migrate to Hugo from Jekyll
---
## Move static content to `static`
Jekyll has a rule that any directory not starting with `_` will be copied as-is to the `_site` output. Hugo keeps all static content under `static`. You should therefore move it all there.
With Jekyll, something that looked like
<root>/
▾ images/
logo.png
should become
<root>/
▾ static/
▾ images/
logo.png
Additionally, you'll want any files that should reside at the root (such as `CNAME`) to be moved to `static`.
## Create your Hugo configuration file
Hugo can read your configuration as JSON, YAML or TOML. Hugo supports parameters custom configuration too. Refer to the [Hugo configuration documentation](/overview/configuration/) for details.
## Set your configuration publish folder to `_site`
The default is for Jekyll to publish to `_site` and for Hugo to publish to `public`. If, like me, you have [`_site` mapped to a git submodule on the `gh-pages` branch](http://blog.blindgaenger.net/generate_github_pages_in_a_submodule.html), you'll want to do one of two alternatives:
1. Change your submodule to point to map `gh-pages` to public instead of `_site` (recommended).
git submodule deinit _site
git rm _site
git submodule add -b gh-pages git@github.com:your-username/your-repo.git public
2. Or, change the Hugo configuration to use `_site` instead of `public`.
{
..
"publishdir": "_site",
..
}
## Convert Jekyll templates to Hugo templates
That's the bulk of the work right here. The documentation is your friend. You should refer to [Jekyll's template documentation](http://jekyllrb.com/docs/templates/) if you need to refresh your memory on how you built your blog and [Hugo's template](/layout/templates/) to learn Hugo's way.
As a single reference data point, converting my templates for [heyitsalex.net](http://heyitsalex.net/) took me no more than a few hours.
## Convert Jekyll plugins to Hugo shortcodes
Jekyll has [plugins](http://jekyllrb.com/docs/plugins/); Hugo has [shortcodes](/doc/shortcodes/). It's fairly trivial to do a port.
### Implementation
As an example, I was using a custom [`image_tag`](https://github.com/alexandre-normand/alexandre-normand/blob/74bb12036a71334fdb7dba84e073382fc06908ec/_plugins/image_tag.rb) plugin to generate figures with caption when running Jekyll. As I read about shortcodes, I found Hugo had a nice built-in shortcode that does exactly the same thing.
Jekyll's plugin:
module Jekyll
class ImageTag < Liquid::Tag
@url = nil
@caption = nil
@class = nil
@link = nil
// Patterns
IMAGE_URL_WITH_CLASS_AND_CAPTION =
IMAGE_URL_WITH_CLASS_AND_CAPTION_AND_LINK = /(\w+)(\s+)((https?:\/\/|\/)(\S+))(\s+)"(.*?)"(\s+)->((https?:\/\/|\/)(\S+))(\s*)/i
IMAGE_URL_WITH_CAPTION = /((https?:\/\/|\/)(\S+))(\s+)"(.*?)"/i
IMAGE_URL_WITH_CLASS = /(\w+)(\s+)((https?:\/\/|\/)(\S+))/i
IMAGE_URL = /((https?:\/\/|\/)(\S+))/i
def initialize(tag_name, markup, tokens)
super
if markup =~ IMAGE_URL_WITH_CLASS_AND_CAPTION_AND_LINK
@class = $1
@url = $3
@caption = $7
@link = $9
elsif markup =~ IMAGE_URL_WITH_CLASS_AND_CAPTION
@class = $1
@url = $3
@caption = $7
elsif markup =~ IMAGE_URL_WITH_CAPTION
@url = $1
@caption = $5
elsif markup =~ IMAGE_URL_WITH_CLASS
@class = $1
@url = $3
elsif markup =~ IMAGE_URL
@url = $1
end
end
def render(context)
if @class
source = "<figure class='#{@class}'>"
else
source = "<figure>"
end
if @link
source += "<a href=\"#{@link}\">"
end
source += "<img src=\"#{@url}\">"
if @link
source += "</a>"
end
source += "<figcaption>#{@caption}</figcaption>" if @caption
source += "</figure>"
source
end
end
end
Liquid::Template.register_tag('image', Jekyll::ImageTag)
is written as this Hugo shortcode:
<!-- image -->
<figure {{ with .Get "class" }}class="{{.}}"{{ end }}>
{{ with .Get "link"}}<a href="{{.}}">{{ end }}
<img src="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}{{ end }}"{{ end }} />
{{ if .Get "link"}}</a>{{ end }}
{{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
<figcaption>{{ if isset .Params "title" }}
{{ .Get "title" }}{{ end }}
{{ if or (.Get "caption") (.Get "attr")}}<p>
{{ .Get "caption" }}
{{ with .Get "attrlink"}}<a href="{{.}}"> {{ end }}
{{ .Get "attr" }}
{{ if .Get "attrlink"}}</a> {{ end }}
</p> {{ end }}
</figcaption>
{{ end }}
</figure>
<!-- image -->
### Usage
I simply changed:
{% image full http://farm5.staticflickr.com/4136/4829260124_57712e570a_o_d.jpg "One of my favorite touristy-type photos. I secretly waited for the good light while we were "having fun" and took this. Only regret: a stupid pole in the top-left corner of the frame I had to clumsily get rid of at post-processing." ->http://www.flickr.com/photos/alexnormand/4829260124/in/set-72157624547713078/ %}
to this (this example uses a slightly extended version named `fig`, different than the built-in `figure`):
{{%/* fig class="full" src="http://farm5.staticflickr.com/4136/4829260124_57712e570a_o_d.jpg" title="One of my favorite touristy-type photos. I secretly waited for the good light while we were having fun and took this. Only regret: a stupid pole in the top-left corner of the frame I had to clumsily get rid of at post-processing." link="http://www.flickr.com/photos/alexnormand/4829260124/in/set-72157624547713078/" */%}}
As a bonus, the shortcode named parameters are, arguably, more readable.
## Finishing touches
### Fix content
Depending on the amount of customization that was done with each post with Jekyll, this step will require more or less effort. There are no hard and fast rules here except that `hugo server --watch` is your friend. Test your changes and fix errors as needed.
### Clean up
You'll want to remove the Jekyll configuration at this point. If you have anything else that isn't used, delete it.
## A practical example in a diff
[Hey, it's Alex](http://heyitsalex.net/) was migrated in less than a _father-with-kids day_ from Jekyll to Hugo. You can see all the changes (and screw-ups) by looking at this [diff](https://github.com/alexandre-normand/alexandre-normand/compare/869d69435bd2665c3fbf5b5c78d4c22759d7613a...b7f6605b1265e83b4b81495423294208cc74d610).

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 KiB

View File

@ -0,0 +1,25 @@
---
title: "NASA Images"
date: 2018-12-27T20:46:49-06:00
tags: ["nasa"]
---
The below images are from the [NASA Image and Video Library](https://images.nasa.gov/) -- indulge yourself, revel in their beauty.
{{< figure
img="sun.jpg"
caption="The Sun is the star at the center of the Solar System. It is a nearly perfect sphere of hot plasma, with internal convective motion that generates a magnetic field via a dynamo process. It is by far the most important source of energy for life on Earth. [Credits](https://images.nasa.gov/details-GSFC_20171208_Archive_e000393.html)."
command="Resize"
options="700x" >}}
{{< figure
img="moon.jpg"
caption="The Moon is an astronomical body that orbits planet Earth and is Earth's only permanent natural satellite. It is the fifth-largest natural satellite in the Solar System, and the largest among planetary satellites relative to the size of the planet that it orbits (its primary). The Moon is after Jupiter's satellite Io the second-densest satellite in the Solar System among those whose densities are known. [Credits](https://images.nasa.gov/details-GSFC_20171208_Archive_e001861.html)."
command="Resize"
options="700x" >}}
{{< figure
img="earth.jpg"
caption="Earth is the third planet from the Sun and the only astronomical object known to harbor life. According to radiometric dating and other sources of evidence, Earth formed over 4.5 billion years ago. Earth's gravity interacts with other objects in space, especially the Sun and the Moon, Earth's only natural satellite. Earth revolves around the Sun in 365.26 days, a period known as an Earth year. During this time, Earth rotates about its axis about 366.26 times. [Credits](https://images.nasa.gov/details-PIA18033.html)."
command="Resize"
options="700x" >}}

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 MiB

View File

@ -0,0 +1,49 @@
---
title: "Quotes by Carl Jung"
date: 2018-12-26T00:29:41-06:00
tags: ["quotes"]
---
{{% blockquote author="Carl Jung" %}}
Even a happy life cannot be without a measure of darkness, and the word happy would lose its meaning if it were not balanced by sadness. It is far better to take things as they come along with patience and equanimity.
{{% /blockquote %}}
{{% blockquote author="Carl Jung" %}}
The least of things with a meaning is worth more in life than the greatest of things without it.
{{% /blockquote %}}
{{% blockquote author="Carl Jung" %}}
Who looks outside, dreams; who looks inside, awakes.
{{% /blockquote %}}
{{% blockquote author="Carl Jung" %}}
Everything that irritates us about others can lead us to an understanding of ourselves.
{{% /blockquote %}}
{{% blockquote author="Carl Jung" %}}
Knowing your own darkness is the best method for dealing with the darknesses of other people.
{{% /blockquote %}}
{{% blockquote author="Carl Jung" %}}
The meeting of two personalities is like the contact of two chemical substances: if there is any reaction, both are transformed.
{{% /blockquote %}}
{{% blockquote author="Carl Jung" %}}
There is no coming to consciousness without pain.
{{% /blockquote %}}
{{% blockquote author="Carl Jung" %}}
As far as we can discern, the sole purpose of human existence is to kindle a light of meaning in the darkness of mere being.
{{% /blockquote %}}
{{% blockquote author="Carl Jung" %}}
We cannot change anything until we accept it. Condemnation does not liberate, it oppresses.
{{% /blockquote %}}
{{% blockquote author="Carl Jung" %}}
In all chaos there is a cosmos, in all disorder a secret order.
{{% /blockquote %}}
{{% blockquote author="Carl Jung" %}}
Show me a sane man and I will cure him for you.
{{% /blockquote %}}

View File

@ -29,9 +29,7 @@
img:not([src*=".svg"]), .colors, iframe, .demo-container { filter: invert(100%) }
</style>
<title>
{{ block "title" . }}
{{ .Title }} | {{ .Site.Title }}
{{ end }}
{{ .Title }} | {{ .Site.Title }}
</title>
{{ if .IsHome }}
<link rel="manifest" href="manifest.json">
@ -66,7 +64,9 @@
{{ range .Site.Menus.nav }}
<li class="pattern">
{{ $active := or ($current.IsMenuCurrent "nav" .) ($current.HasMenuCurrent "nav" .) }}
{{/* TODO highlight Blog nav item when on post pages */}}
{{ $active = or $active (eq .Name $current.Title) }}
{{ $active = or $active (and (eq .Name "Blog") (eq $current.Section "post")) }}
{{ $active = or $active (and (eq .Name "Tags") (eq $current.Section "tags")) }}
<a href="{{ .URL }}" {{ if $active }}aria-current="page"{{ end }}>
<svg class="bookmark-icon" aria-hidden="true" focusable="false" viewBox="0 0 40 50">
<use xlink:href="#bookmark"></use>

View File

@ -0,0 +1,26 @@
{{ define "main" }}
<main id="main">
<h1>
{{ .Title }}
</h1>
<ul class="patterns-list">
{{ $type := .Type }}
{{ range $key, $value := .Data.Terms.ByCount }}
{{ $name := .Name }}
{{ $count := .Count }}
{{ with $.Site.GetPage (printf "/%s/%s" $type $name) }}
<li>
<h2>
<a href="{{ .Permalink }}">
<svg class="tag-icon" aria-hidden="true" viewBox="0 0 177.16535 177.16535" focusable="false">
<use xlink:href="#tag"></use>
</svg>
{{ printf "(%d) %s" $count $name }}
</a>
</h2>
</li>
{{ end }}
{{ end }}
</ul>
</main>
{{ end }}

View File

@ -1,10 +0,0 @@
<li>
<h2>
<a href="{{ .Permalink }}">
<svg class="bookmark" aria-hidden="true" viewBox="0 0 40 50" focusable="false">
<use xlink:href="#bookmark"></use>
</svg>
{{ .Title }}
</a>
</h2>
</li>

View File

@ -6,6 +6,9 @@
</svg>
{{ .Title }}
</h1>
<div class="date">
<strong aria-hidden="true">Publish date: </strong>{{ .PublishDate.Format $.Site.Params.dateFormat }}
</div>
{{ if isset .Params "tags" }}
<div class="tags">
<strong aria-hidden="true">Tags: </strong>
@ -15,12 +18,13 @@
<svg class="tag-icon" aria-hidden="true" viewBox="0 0 177.16535 177.16535" focusable="false">
<use xlink:href="#tag"></use>
</svg>
<a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</a>
<a href="{{ "/tags/" | absLangURL }}{{ . | urlize }}">{{ . }}</a>
</li>
{{ end }}
</ul>
</div>
{{ end }}
{{ if ne .Params.TOC false }}
{{ partial "toc" . }}
{{ end }}

View File

@ -0,0 +1,10 @@
{{ $quote := .Inner }}
{{ $quote = replace $quote "<p>" "" }}
{{ $quote = replace $quote "</p>" "" }}
{{ $quote = safeHTML $quote }}
<blockquote class="blockquote">
<p>{{ $quote }}</p>
{{ with (.Get "author") }}
<footer>{{ . }}</footer>
{{ end }}
</blockquote>

View File

@ -1,7 +1,23 @@
{{ $caption := .Get "caption" }}
<figure role="group" aria-describedby="caption-{{ $caption | md5 }}">
{{ .Inner }}
<figcaption id="caption-{{ $caption | md5 }}">
{{ .Get "caption" | markdownify }}
{{ $original := .Page.Resources.GetMatch (printf "*%s*" (.Get "img")) }}
{{ $new := "" }}
{{ if eq (.Get "command") "Fit" }}
{{ $new = $original.Fit (.Get "options") }}
{{ else if eq (.Get "command") "Fill" }}
{{ $new = $original.Fill (.Get "options") }}
{{ else if eq (.Get "command") "Resize" }}
{{ $new = $original.Resize (.Get "options") }}
{{ else if eq (.Get "command") "Original" }}
{{ $new = $original }}
{{ else }}
{{ errorf "Invalid image processing command: Must be one of Fit, Fill, Resize, Original." }}
{{ end }}
<figure role="group" aria-describedby="caption-{{ (.Get "caption") | md5 }}">
<a href="{{ $original.Permalink }}" class="img-link">
<img src="{{ $new.Permalink }}">
</a>
<figcaption id="caption-{{ (.Get "caption") | md5 }}">
{{ (.Get "caption") | markdownify }}
</figcaption>
</figure>

View File

@ -1,18 +0,0 @@
{{ define "title" }}
Patterns tagged {{ .Title }} | {{ .Site.Title }}
{{ end }}
{{ define "main" }}
<main id="main">
<h1>
<svg class="tag-icon" aria-hidden="true" viewBox="0 0 177.16535 177.16535" focusable="false">
<use xlink:href="#tag"></use>
</svg>
Tagged &#x201c;{{ .Title }}&#x201d;
</h1>
<ul class="patterns-list">
{{ range .Data.Pages }}
{{ .Render "li"}}
{{ end }}
</ul>
</main>
{{ end }}

View File

@ -59,6 +59,9 @@ img {
max-width: 100%;
max-height: 50vh;
}
.img-link {
border-bottom: none;
}
p img {
margin: 0.75rem 0;
}
@ -461,6 +464,13 @@ caption {
white-space: nowrap;
margin: 0 0.25rem 0 0;
}
/* Date */
.date {
margin-top: 0;
font-size: 0.85rem;
}
/* Notes and warnings */
.note {