Skip to content

Commit

Permalink
feat: add hygen for pages and posts
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Jan 11, 2022
1 parent 7bf68a4 commit b9d1507
Show file tree
Hide file tree
Showing 7 changed files with 694 additions and 10 deletions.
31 changes: 31 additions & 0 deletions .hygen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { v4: uuidv4 } = require("uuid");
const { paramCase } = require("change-case");

const today = new Date();

const getYear = today.getFullYear();
const getMonth = today.getMonth() + 1;
const getDay = today.getDate();

const padLeft = (num) => num < 10 ? "0" + num : "" + num;

const getDate = `${getYear}-${padLeft(getMonth)}-${padLeft(getDay)}`;

const IMAGE_PATH = "/_images/";
const DEFAULT_THUMB = IMAGE_PATH + "default-thumb.png";

module.exports = {
helpers: {
getPostFileName: (locals) => {
if (locals.isDraft === "yes") {
return `DRAFT-${locals.permalink ? locals.permalink : uuidv4() }`;
}

const permalink = locals.permalink || paramCase(locals.title);
return `${getYear}/${getDate}-${permalink}`;
},
getYear,
IMAGE_PATH,
DEFAULT_THUMB,
}
}
24 changes: 24 additions & 0 deletions _templates/page/with-prompt/hello.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
to: input/pages/<%= h.changeCase.param(permalink || title) %>.md
---
---
title: "<%= title %>"
<% if (locals.meta_title) { -%>
meta_title: "<%= meta_title %>"
<% } -%>
meta_description: "<%= meta_description || "TODO: Write a description" %>"
featured_img: <%= featured_img ? `${h.IMAGE_PATH}${h.getYear}/${featured_img}` : h.DEFAULT_THUMB %>
<% if (locals.canonical_link) { -%>
canonical_link: <%= canonical_link %>
<% } -%>
---

Go forth 🙌

{% warning %}Warning panel{% endwarning %}

{% info %}Info panel{% endinfo %}

{% bigtext %}Big text{% endbigtext %}

{% caption %}Caption text{% endcaption %}
32 changes: 32 additions & 0 deletions _templates/page/with-prompt/prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = [
{
type: 'input',
name: 'title',
message: "Page title"
},
{
type: 'input',
name: 'permalink',
message: "Page permalink"
},
{
type: 'input',
name: 'meta_title',
message: "Meta title"
},
{
type: 'input',
name: 'meta_description',
message: "Meta description"
},
{
type: 'input',
name: 'featured_img',
message: "Featured image file name"
},
{
type: 'input',
name: 'canonical_link',
message: "Canonical link"
}
]
41 changes: 41 additions & 0 deletions _templates/post/with-prompt/hello.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
to: input/posts/<%= h.getPostFileName(locals) %>.md
---
---
title: "<%= title || "TODO: Write an title" %>"
<% if (locals.meta_title) { -%>
meta_title: "<%= meta_title %>"
<% } -%>
excerpt: "<%= excerpt || "TODO: Write an excerpt" %>"
<% if (locals.meta_description) { -%>
meta_description: "<%= meta_description %>"
<% } -%>
featured_img: <%= featured_img ? `${h.IMAGE_PATH}${h.getYear}/${featured_img}` : h.DEFAULT_THUMB %>
<% if (locals.tags.length) { -%>
tags: ["<%- tags.join('\", \"') %>"]
<% } -%>
<% if (locals.link_to) { -%>
link_to: <%= link_to %>
<% } -%>
<% if (locals.canonical_link) { -%>
canonical_link: <%= canonical_link %>
<% } -%>
<% if (locals.isDraft === "yes") { -%>
eleventyExcludeFromCollections: true
<% } -%>
---

Go forth 🙌

<img src="/_images/<%= h.getYear %>/featured_image.jpg" class="aligncenter" alt="">
{% caption %}Caption text{% endcaption %}

{% warning %}Warning panel{% endwarning %}

{% info %}Info panel{% endinfo %}

{% bigtext %}Big text{% endbigtext %}

{% h2br %}References{% endh2br %}

-
53 changes: 53 additions & 0 deletions _templates/post/with-prompt/prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module.exports = [
{
type: 'select',
name: 'isDraft',
message: "Is this post a draft?",
choices: ["yes", "no"]
},
{
type: 'input',
name: 'permalink',
message: "Post permalink"
},
{
type: 'input',
name: 'title',
message: "Post title"
},
{
type: 'input',
name: 'meta_title',
message: "Meta title"
},
{
type: 'input',
name: 'excerpt',
message: "Post excerpt"
},
{
type: 'input',
name: 'meta_description',
message: "Meta description"
},
{
type: 'input',
name: 'featured_img',
message: "Featured image file name"
},
{
type: 'list',
name: 'tags',
message: "Enter tags, separated by commas"
},
{
type: 'input',
name: 'link_to',
message: "Link out"
},
{
type: 'input',
name: 'canonical_link',
message: "Canonical link"
}
]
Loading

0 comments on commit b9d1507

Please sign in to comment.