Skip to content

Instantly share code, notes, and snippets.

@expalmer
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save expalmer/05c0ec27cbe5d1324e16 to your computer and use it in GitHub Desktop.
Save expalmer/05c0ec27cbe5d1324e16 to your computer and use it in GitHub Desktop.
blog - Metalsmith, um extremamente simples gerador de páginas estáticas feito em Javascript
* {
padding: 0;
margin: 0;
}
body {
margin: 30px auto;
max-width: 600px;
text-align: center;
font-size: 100%;
font-family: 'Georgia', 'Arial', serif;
color: #111;
background: #fff;
}
a {
color: #999;
}
header,
section,
article,
footer {
margin-top: -1px;
padding: 20px;
border: solid 1px #eee;
}
ul li {
list-style: none;
}
ul li a {
display: inline-block;
margin: 5px;
color: #FF0050;
}
---
template: index.hbt
---
Corpo da página index
---
title: Meu Primeiro Post com Metalsmith
template: posts.hbt
---
Corpo do Post 1
---
title: Meu Segundo Post
template: posts.hbt
---
Corpo do Post 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Blog Index</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
<h1>Index</h1>
</header>
<section>
{{{contents}}}
</section>
<section>
<h2>Lista dos Posts</h2>
<ul>
{{#each collections.posts }}
<li>
<a href="{{this.path}}/index.html" title="{{this.path}}">{{this.title}}</a>
</li>
{{/each}}
</ul>
</section>
<footer>
made with <a href="http://www.metalsmith.io/">metalsmith</a>
</footer>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Blog Posts</title>
<link rel="stylesheet" href="../css/style.css">
</head>
<body>
<header>
<a href="../index.html">Voltar para o Index</a>
</header>
<article>
<h1>{{this.title}}</h1>
{{{contents}}}
</article>
<footer>
made with <a href="http://www.metalsmith.io/">metalsmith</a>
</footer>
</body>
</html>
[blog]
--- index.js
--- package.json
--- [src]
------- index.md
------- [posts]
------------- post-1.md
------------- post-2.md
--- [templates]
------- index.hbt
------- posts.hbt
var Metalsmith = require('metalsmith');
var collections = require('metalsmith-collections');
var markdown = require('metalsmith-markdown');
var templates = require('metalsmith-templates');
var permalinks = require('metalsmith-permalinks');
Metalsmith(__dirname)
.use(collections({ // nos dará acesso a um objeto chamado 'collections' ...
posts: { // ... com todos os posts
pattern: 'posts/*.md', // aqui é o lugar onde estão nossos posts
sortBy: 'date', // ordenar por data
reverse: true // ordenar da data mais recente para a mais antiga
}
}))
.use(markdown()) // vai ler todos arquivos .md e transformar em um objeto
.use(permalinks({ // vai mudar o arquivo destino no padrão {title}/index.html
pattern: ':title',
relative: false
}))
.use(templates('handlebars')) // nossos objetos serão passados para o handlebars
.destination('./build') // diretório destino
.build(function(err, files) { // escreve os aquivos no diretório build
if (err) { throw err; } // um handler de erro, sempre é bom
});
{
"name": "blog",
"description": "meu blog legal",
"version": "0.0.1",
"dependencies": {
"handlebars": "^2.0.0",
"metalsmith": "^0.11.0",
"metalsmith-collections": "^0.6.0",
"metalsmith-markdown": "^0.2.1",
"metalsmith-permalinks": "^0.4.0",
"metalsmith-templates": "^0.5.2",
"metasmith": "0.0.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment