Skip to content

Commit

Permalink
Initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
h-enk committed Nov 27, 2019
0 parents commit b877ad9
Show file tree
Hide file tree
Showing 27 changed files with 4,930 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/public
/node_modules

/functions
/resources
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2017 Indigo Tree

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
154 changes: 154 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
[![Atlas, Hugo Boilerplate](https://atlas.indigotree.co.uk/images/github-banner.png)](https://github.com/indigotree/atlas)

![](http://forthebadge.com/images/badges/uses-badges.svg) ![](http://forthebadge.com/images/badges/built-by-developers.svg) ![](http://forthebadge.com/images/badges/gluten-free.svg)

# Atlas

The [Hugo](https://gohugo.io/) boilerplate we use for our projects.

**Disclaimer** - This boilerplate has been heavily integrated with [Netlify](https://www.netlify.com/), and therefore many features are specific to the Netlify platform and may not work with other hosting providers.

**Disclaimer** - Atlas is a boilerplate (starter kit) for bespoke Hugo projects. It's not a Hugo theme and cannot be placed inside the `/themes` directory. Check the [theme](#themes) docs for more information.

## Features

Atlas provides the following features out of the box:

* Pre configured support for Hugo Pipes, with SASS and Autoprefixer
* Environment driven `robots.txt` file (disallows robots on everything other than production)
* Base HTML templates with easy customisation/extension
* [Configuration](/netlify.toml) for Netlify deployments
* [Better defaults](#security-headers) for configuring HTTPS
* [Better redirects](#redirects) with Netlify instead of `<meta http-equiv="refresh">`

## Prerequisite

Atlas does not include a copy of the `hugo` binary. You will need to [install Hugo](https://gohugo.io/getting-started/installing/) first you can run any of the [commands](#available-commands) mentioned below. It does however include a Hugo version number as part of the `netlify.toml` file to specify the version of Hugo to use when building on Netlify.

## Getting Started

To get started, you can either clone the repository, or deploy straight to [Netlify](#deploy-to-netlify). Then run the following from the project root:

```
npm install
npm run server
```

### Available Commands

There are 3 commands available:

* `npm run build` - Builds assets (sass, js, fonts, images) and runs `hugo`
* `npm run build:preview` - The same as `build`, but runs `hugo --buildDrafts --buildFuture`
* `npm run server` - Runs BrowserSync and watches for changes, running `build` when changes are detected

## Robots.txt

A default robots.txt can be found at `/layouts/robots.txt` which is configured to disallow crawlers when the `HUGO_ENV` environment variable is **not** set to `"production"`.

The default behaviour is to disallow search engines on "branch" deployments. If you're using split testing, you will need to modify the default robots.txt template to ensure your branch deployments can be indexed.

## Functions

Atlas has `netlify-lambda` installed out of the box to make working with Netlify Functions that much easier. Functions should be made inside `src/lambda` and should end in the `.js` extension. They will be compiled into `/functions` where Netlify will recognise them and deploy them automatically.

Here is an example that you can start from:

```
exports.handler = (event, context, callback) => {
callback(null, {
statusCode: 200,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: "Hi from Lambda."
})
});
}
```

## Headers

Headers can be configured within `/layouts/index.headers`, which is then built to `/public/_headers`.

This is a Netlify feature. Learn more about [Headers with Netlify](https://www.netlify.com/docs/headers-and-basic-auth/).

### Security Headers

Atlas comes with some default headers to help you better protect your site. The default headers we include are: [X-Frame-Options](https://scotthelme.co.uk/hardening-your-http-response-headers/#x-frame-options), [X-XSS-Protection](https://scotthelme.co.uk/hardening-your-http-response-headers/#x-xss-protection), [X-Content-Type-Options](https://scotthelme.co.uk/hardening-your-http-response-headers/#x-content-type-options), [Referrer-Policy](https://scotthelme.co.uk/a-new-security-header-referrer-policy/).

These headers are configured with the following values:

```
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Referrer-Policy: origin-when-cross-origin
```

## Redirects

Redirect rules can be appended to `/layouts/index.redirects`, which is then built to `/public/_redirects`.

This is a Netlify feature. Learn more about [Netlify Redirects](https://www.netlify.com/docs/redirects/).

### Aliases

Hugo [Aliases](https://gohugo.io/content-management/urls/#aliases) are usually handled by `<meta http-equiv="refresh" ...>` tags. These have been disabled within `config.toml` with `disableAliases = true`, and instead are handled by [Netlify Redirects](https://www.netlify.com/docs/redirects/). This is handled automatically and you should continue to add aliases as described in the Hugo documentation.

## Themes

Atlas is a boilerplate (starter kit) designed to aid bespoke Hugo development. Using existing themes with Atlas is possible, but unsupported.

Atlas files will take priority over your theme due to the order Hugo looks for files. For this reason, you will have to remove most of the files inside `/layouts` with the exception of `_headers`, `_redirects` and `robots.txt`.

If you wish the develop your site as a theme inside Atlas, you can copy `/layouts` into your theme and update the references within the `gulpfile.babel.js`.


## File Structure

```
│ │
| └──── /assets - Source files for assets (SASS, JS, Images, Fonts etc)
└──── /layouts - Template files
│ │ 404.html - 404 Template
│ │ index.headers - Custom Netlify HTTP headers
│ │ index.redirects - Custom Netlify redirect rules
│ │ robots.txt - Template for robots.txt
│ │
│ └──── /_default - Base templates for list & singular pages
│ │ │ baseof.html - Base template
│ │ │ list.html - List/taxonomy template
│ │ │ single.html - Singular page/post template
│ │
│ └──── /partials - Partials
│ │
│ └──── /site - Site partials loaded into _default/baseof.html template
│ │ meta.html - Site <meta> tags
│ │ header.html - Sites primary <header>
│ │ footer.html - Sites primary <footer>
│ │ scripts.html - JavaScript <script> referenced before closing </body>
│ │ styles.html - Stylesheets referenced before closing </head>
│ │
│ └──── /static - Hugo static resources
│ .gitignore
│ LICENSE
│ README.md
│ config.toml - Hugo configuration
│ postcss.config.js - PostCSS configuration for Hugo Pipes
│ netlify.toml - Netlify configuration
│ package.json
```

## Deploy to Netlify

You can deploy directly to Netlify using this button:

[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/indigotree/atlas)

## License

MIT © [Indigo Tree](https://indigotree.co.uk)
6 changes: 6 additions & 0 deletions archetypes/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: "{{ replace .TranslationBaseName "-" " " | title }}"
date: {{ .Date }}
draft: true
---

Empty file added assets/js/app.js
Empty file.
Empty file added assets/lambda/.gitignore
Empty file.
11 changes: 11 additions & 0 deletions assets/lambda/hi-from-lambda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.handler = (event, context, callback) => {
callback(null, {
statusCode: 200,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: "Hi from Lambda."
})
});
}
5 changes: 5 additions & 0 deletions assets/sass/app.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$body-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";

body {
font-family: $body-font;
}
34 changes: 34 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
baseURL = "/"
languageCode = "en-gb"
title = "Atlas"

enableRobotsTXT = true
disableAliases = true
enableEmoji = true

[params]
disallow_search_engines = false # set robots.txt to disallow everything

# add redirects/headers
[outputs]
home = ["HTML", "RSS", "REDIRECTS", "HEADERS"]

# remove .{ext} from text/netlify
[mediaTypes."text/netlify"]
suffixes = [""]
delimiter = ""

# add output format for netlify _redirects
[outputFormats.REDIRECTS]
mediatype = "text/netlify"
baseName = "_redirects"
isPlainText = true
notAlternative = true

# add output format for netlify _headers
[outputFormats.HEADERS]
mediatype = "text/netlify"
baseName = "_headers"
isPlainText = true
notAlternative = true

4 changes: 4 additions & 0 deletions content/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: ""
date: 2019-03-17T18:18:43Z
---
19 changes: 19 additions & 0 deletions content/lorem-dolor-sit-amet/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: "Lorem ipsum dolor sit amet"
date: 2019-11-27T08:50:42+01:00
draft: false
---

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu mattis libero, at ornare felis. Etiam pretium ac mauris quis elementum. Sed ultricies tincidunt diam nec finibus. In dolor augue, fermentum quis mi ut, fringilla gravida elit.

Ut luctus elit sed lacus vulputate aliquam. Donec pretium, nisi sed volutpat maximus, dolor sapien pharetra erat, non porttitor lorem metus nec arcu. Curabitur aliquet sem sed nulla lobortis, et bibendum mi tincidunt. Nullam ut euismod libero, elementum ultricies nulla.

Aliquam vehicula nisl molestie nibh posuere volutpat. Phasellus pulvinar tempus nibh at semper. Morbi et risus ornare, tincidunt neque commodo, commodo eros. Integer consectetur nibh ac risus finibus mollis. Vivamus venenatis libero et pretium auctor.

Maecenas posuere congue felis ut ultricies. Cras vitae ante tortor. Ut aliquam, augue in sodales aliquam, justo purus dignissim elit, vel malesuada enim nisl eu odio. Curabitur facilisis quis leo vitae pharetra. Donec vitae sapien convallis, tincidunt ipsum nec, tincidunt mi.

Nulla luctus pharetra eros sit amet posuere. Proin tempus nibh venenatis risus blandit pulvinar. Sed commodo purus at dui venenatis lacinia. Duis maximus augue in nibh vehicula, non varius lectus gravida. Suspendisse nec urna egestas, ultricies lectus quis, commodo velit.

Proin et vestibulum enim, et facilisis nisi. Morbi faucibus, risus ac lacinia vulputate, enim quam malesuada enim, non rutrum mauris sem eu libero. Vivamus porta accumsan leo sit amet elementum. Curabitur sit amet dignissim dolor.

:smiley_cat:
8 changes: 8 additions & 0 deletions layouts/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{ define "main" }}

<article>
<h1>Page Not Found!</h1>
<p>The page you requested could not be found.</p>
</article>

{{ end }}
33 changes: 33 additions & 0 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!doctype html>
<html lang="{{ .Site.LanguageCode | default "en" }}">
<head>

{{ block "site/meta" . }}{{ partial "site/meta.html" . }}{{ end }}

<title>{{ block "title" . }}
{{- with .Title }}{{ . }} | {{ end }}{{ .Site.Title -}}
{{ end }}</title>

{{ range .AlternativeOutputFormats }}
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}">
{{ end }}

{{ block "site/styles" . }}{{ partial "site/styles.html" . }}{{ end }}

</head>
<body>

{{ block "header" . }}{{ partial "site/header.html" . }}{{ end }}

<main class="site-main" role="main">

{{ block "main" . }}{{ end }}

</main>

{{ block "footer" . }}{{ partial "site/footer.html" . }}{{ end }}

{{ block "site/scripts" . }}{{ partial "site/scripts.html" . }}{{ end }}

</body>
</html>
12 changes: 12 additions & 0 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{ define "main" }}

{{ range .Paginator.Pages }}
<article>
<h2><a href="{{ .Permalink }}">{{ .Title }}</a></h2>
{{ .Content }}
</article>
{{ end }}

{{ template "_internal/pagination.html" . }}

{{ end }}
8 changes: 8 additions & 0 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{ define "main" }}

<article>
<h1>{{ .Title }}</h1>
{{ .Content }}
</article>

{{ end }}
5 changes: 5 additions & 0 deletions layouts/index.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Referrer-Policy: origin-when-cross-origin
6 changes: 6 additions & 0 deletions layouts/index.redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# redirects for Netlify - https://www.netlify.com/docs/redirects/
{{- range $p := .Site.Pages -}}
{{- range .Aliases }}
{{ . }} {{ $p.RelPermalink -}}
{{- end }}
{{- end -}}
7 changes: 7 additions & 0 deletions layouts/partials/site/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<footer class="site-footer" role="contentinfo">

<p class="site-footer__copyright">
&copy; {{ now.Format "2006" }} &middot; <a href="{{ .Site.BaseURL }}">{{ .Site.Title }}</a>
</p>

</footer>
5 changes: 5 additions & 0 deletions layouts/partials/site/header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<header class="site-header" role="banner">

<strong><a href="{{ .Site.BaseURL }}">{{ .Site.Title }}</a></strong>

</header>
6 changes: 6 additions & 0 deletions layouts/partials/site/meta.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

{{ with .Description }}<meta name="description" content="{{ . }}">{{ end }}
{{ .Hugo.Generator }}
3 changes: 3 additions & 0 deletions layouts/partials/site/scripts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ $s := resources.Get "js/app.js" | minify }}

<script src="{{ $s.Permalink }}"></script>
3 changes: 3 additions & 0 deletions layouts/partials/site/styles.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ $s := resources.Get "sass/app.scss" | toCSS | postCSS (dict "config" "postcss.config.js") | minify }}

<link rel="stylesheet" href="{{ $s.Permalink }}" />
6 changes: 6 additions & 0 deletions layouts/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
User-agent: *
{{- if .Site.Params.disallow_search_engines }}
Disallow: /
{{ else }}
Disallow: {{ if ne (getenv "HUGO_ENV") "production" }}/{{ end }}
{{ end }}
17 changes: 17 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[build]
command = "hugo -b $URL && npm run build:functions"
publish = "public"
functions = "functions"

[build.environment]
HUGO_VERSION = "0.59.1"

[context.production.environment]
HUGO_ENV = "production"
NODE_ENV = "production"

[context.deploy-preview]
command = "hugo -b $DEPLOY_PRIME_URL"

[context.branch-deploy]
command = "hugo -b $DEPLOY_PRIME_URL"
Loading

0 comments on commit b877ad9

Please sign in to comment.