Skip to content

Commit

Permalink
Remove the need for css preprocessing, remove gulp entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddarnes committed Jul 24, 2019
1 parent b195e8f commit 64f5186
Show file tree
Hide file tree
Showing 12 changed files with 1,127 additions and 1,639 deletions.
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.hbs]
insert_final_newline = false

[*.json]
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[Makefile]
indent_style = tab
81 changes: 40 additions & 41 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,66 @@
require('dotenv').config();
require("dotenv").config();

const cleanCSS = require('clean-css');
const fs = require('fs');
const pluginRSS = require('@11ty/eleventy-plugin-rss');
const localImages = require('eleventy-plugin-local-images');
const ghostContentAPI = require('@tryghost/content-api');
const cleanCSS = require("clean-css");
const fs = require("fs");
const pluginRSS = require("@11ty/eleventy-plugin-rss");
const localImages = require("eleventy-plugin-local-images");
const ghostContentAPI = require("@tryghost/content-api");

const htmlMinTransform = require('./src/transforms/html-min-transform.js');
const htmlMinTransform = require("./src/transforms/html-min-transform.js");

// Init Ghost API
const api = new ghostContentAPI({
url: process.env.GHOST_CONTENT_API_URL,
url: process.env.GHOST_API_URL,
key: process.env.GHOST_CONTENT_API_KEY,
version: 'v2'
version: "v2"
});

// Strip Ghost domain from urls
// if you're using a custom url for this static site
const stripDomain = url => {
return url.replace(process.env.GHOST_CONTENT_API_URL, '');
return url.replace(process.env.GHOST_API_URL, "");
};

module.exports = function(config) {
// Minify HTML
config.addTransform('htmlmin', htmlMinTransform);
config.addTransform("htmlmin", htmlMinTransform);

// Assist RSS feed template
config.addPlugin(pluginRSS);

// Copy images over from Ghost
config.addPlugin(localImages, {
distPath: 'dist',
assetPath: '/assets/images',
selector: 'img',
distPath: "dist",
assetPath: "/assets/images",
selector: "img",
verbose: false
});

// Inline CSS
config.addFilter('cssmin', code => {
config.addFilter("cssmin", code => {
return new cleanCSS({}).minify(code).styles;
});

config.addFilter('getReadingTime', text => {
config.addFilter("getReadingTime", text => {
const wordsPerMinute = 200;
const numberOfWords = text.split(/\s/g).length;
return Math.ceil(numberOfWords / wordsPerMinute);
});

// Date formatting filter
config.addFilter('htmlDateString', dateObj => {
return new Date(dateObj).toISOString().split('T')[0];
config.addFilter("htmlDateString", dateObj => {
return new Date(dateObj).toISOString().split("T")[0];
});

// Don't ignore the same files ignored in the git repo
config.setUseGitIgnore(false);

// Get all pages, called 'docs' to prevent
// conflicting the eleventy page object
config.addCollection('docs', async function(collection) {
config.addCollection("docs", async function(collection) {
collection = await api.pages
.browse({
include: 'authors',
limit: 'all'
include: "authors",
limit: "all"
})
.catch(err => {
console.error(err);
Expand All @@ -80,11 +79,11 @@ module.exports = function(config) {
});

// Get all posts
config.addCollection('posts', async function(collection) {
config.addCollection("posts", async function(collection) {
collection = await api.posts
.browse({
include: 'tags,authors',
limit: 'all'
include: "tags,authors",
limit: "all"
})
.catch(err => {
console.error(err);
Expand All @@ -107,10 +106,10 @@ module.exports = function(config) {
});

// Get all authors
config.addCollection('authors', async function(collection) {
config.addCollection("authors", async function(collection) {
collection = await api.authors
.browse({
limit: 'all'
limit: "all"
})
.catch(err => {
console.error(err);
Expand All @@ -119,8 +118,8 @@ module.exports = function(config) {
// Get all posts with their authors attached
const posts = await api.posts
.browse({
include: 'authors',
limit: 'all'
include: "authors",
limit: "all"
})
.catch(err => {
console.error(err);
Expand All @@ -143,11 +142,11 @@ module.exports = function(config) {
});

// Get all tags
config.addCollection('tags', async function(collection) {
config.addCollection("tags", async function(collection) {
collection = await api.tags
.browse({
include: 'count.posts',
limit: 'all'
include: "count.posts",
limit: "all"
})
.catch(err => {
console.error(err);
Expand All @@ -156,8 +155,8 @@ module.exports = function(config) {
// Get all posts with their tags attached
const posts = await api.posts
.browse({
include: 'tags,authors',
limit: 'all'
include: "tags,authors",
limit: "all"
})
.catch(err => {
console.error(err);
Expand All @@ -183,9 +182,9 @@ module.exports = function(config) {
config.setBrowserSyncConfig({
callbacks: {
ready: (err, bs) => {
const content_404 = fs.readFileSync('dist/404.html');
const content_404 = fs.readFileSync("dist/404.html");

bs.addMiddleware('*', (req, res) => {
bs.addMiddleware("*", (req, res) => {
// Provides the 404 content without redirect.
res.write(content_404);
res.end();
Expand All @@ -197,14 +196,14 @@ module.exports = function(config) {
// Eleventy configuration
return {
dir: {
input: 'src',
output: 'dist'
input: "src",
output: "dist"
},

// Files read by Eleventy, add as needed
templateFormats: ['css', 'njk', 'md', 'txt'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
templateFormats: ["css", "njk", "md", "txt"],
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
passthroughFileCopy: true
};
};
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
GHOST_CONTENT_API_URL=https://eleventy.ghost.io
GHOST_API_URL=https://eleventy.ghost.io
GHOST_CONTENT_API_KEY=b28bdbe3d9799061a92b870bb4
SITE_URL=http://localhost:8080
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ typings/

# Eleventy Custom
.cache/
public
yarn-error.log
.netlify/
/dist
/src/_includes/css
dist
6 changes: 0 additions & 6 deletions .prettierrc

This file was deleted.

21 changes: 0 additions & 21 deletions gulpfile.js

This file was deleted.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": ".eleventy.js",
"scripts": {
"start": "yarn run dev",
"dev": "gulp build & gulp watch & cross-env ELEVENTY_ENV=dev eleventy --serve",
"build": "gulp build & cross-env ELEVENTY_ENV=prod eleventy",
"dev": "cross-env ELEVENTY_ENV=dev eleventy --serve",
"build": "cross-env ELEVENTY_ENV=prod eleventy",
"test": "yarn run build"
},
"repository": {
Expand Down Expand Up @@ -37,9 +37,6 @@
"cross-env": "^5.2.0",
"dotenv": "^8.0.0",
"eleventy-plugin-local-images": "^0.2.0",
"gulp": "^4.0.2",
"gulp-sass": "^4.0.2",
"html-minifier": "^4.0.0",
"sanitize.css": "^11.0.0"
"html-minifier": "^4.0.0"
}
}
12 changes: 7 additions & 5 deletions src/_data/site.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
const ghostContentAPI = require('@tryghost/content-api');
require('dotenv').config();
require("dotenv").config();

const ghostContentAPI = require("@tryghost/content-api");

// Init Ghost API
const api = new ghostContentAPI({
url: process.env.GHOST_CONTENT_API_URL,
url: process.env.GHOST_API_URL,
key: process.env.GHOST_CONTENT_API_KEY,
version: 'v2'
version: "v2"
});

// Get all site information
module.exports = async function() {
const siteData = await api.settings
.browse({
include: 'icon'
include: "icon,url"
})
.catch(err => {
console.error(err);
});

if (process.env.SITE_URL) siteData.url = process.env.SITE_URL;

return siteData;
};
Loading

0 comments on commit 64f5186

Please sign in to comment.