New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

balrog

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

balrog - npm Package Compare versions

Comparing version

to
1.0.1

lib/archive.js

1

config.JSON
{
"source": "",
"output": "",
"siteDir": "",
"templateDir": "",

@@ -5,0 +6,0 @@ "templates": {},

@@ -13,2 +13,3 @@ var fs = require('fs')

var makePage = require('./pagination.js')
var formatHeader = require('./format-header.js')

@@ -53,6 +54,5 @@ var readFile = fs.readFileSync.bind(fs)

collect(sourceDir, function (err, collection) {
cpr(sourceDir, outputDir, {
deleteFirst: true,
overwrite: true,
deleteFirst: false,
overwrite: false,
confirm: true

@@ -64,3 +64,3 @@ }, function (err, files) {

var filesAndContent = parseMarkdownFiles(fullPaths, opts)
makePage(filesAndContent, opts) // in process, wait for it!
makePage(filesAndContent, opts) // make blog feed pages

@@ -72,5 +72,23 @@ var hadError = false

// handle non .md Pages
// duplicating this action, yolo
// fullPaths.forEach(function(path) {
// if (path.match('.html')) {
// console.log("PATH", path)
// var pagePath = removeDirPrefix(path, opts)
// var template = chooseTemplate(pagePath, opts.templates) || 'main'
// var content = readFile(path).toString('utf-8')
// console.log('content', content)
// console.log('template', template)
// var htmlOutput = tpl.templates[template](content)
// console.log(htmlOutput)
// writeFile('site/' + pagePath , htmlOutput)
// }
// })
filesAndContent.forEach(function (page) {
var pagePath = removeDirPrefix(page.input, opts)
var template = chooseTemplate(pagePath, opts.templates) || 'main'
if (!pagePath.match("blog")) page = formatHeader(page, opts)
var htmlOutput = tpl.templates[template](page.content)

@@ -77,0 +95,0 @@ writeFile(page.output, htmlOutput)

80

lib/pagination.js

@@ -9,2 +9,5 @@ var handlebars = require('handlebars')

var chooseTemplate = require('./choose-template')
var formatHeader = require('./format-header.js')
var createArchive = require('./archive.js')
var buildHome = require('./build-homepage.js')

@@ -26,33 +29,44 @@ var writeFile = fs.writeFileSync.bind(fs)

generatePages(totalPages, opts, posts)
function generatePages(totalPages, opts, posts) {
createArchive(posts, opts)
buildHome(posts[0], opts)
posts.forEach(function(post, opts) {
return formatHeader(post, opts)
})
generateTemplates(opts, function (err, tpl) {
if (err) return console.log(err) // callback(err)
mkdirp('site/blog/page/', function() {
for (var i = 0; i < totalPages; i++) {
if (ppp === totalPosts && i === 1) return
var pagesPosts = []
pagesPosts.push(posts.slice((i * ppp), ((i + 1) * ppp)))
var content = { "posts": pagesPosts.pop(), "page": i, "previous": preURL(i), "next": nextURL(i) }
var content = { "posts": pagesPosts.pop(),
"page": i,
"previous": preURL(i),
"next": nextURL(i),
"pagination": true
}
if (ppp > totalPages) content.pagination = false
var pagePath = determinePage(i)
var template = chooseTemplate(pagePath, opts.templates) || 'main'
var template = chooseTemplate(pagePath, opts.templates) || 'feed'
var htmlOutput = tpl.templates[template](content)
if (opts.partialsDir) {
$ = cheerio.load(htmlOutput)
if (i === 0) $('a.turn-previous').addClass('end-of-pages').html()
if (i === totalPages - 1) $('a.turn-next').addClass('end-of-pages').html()
if (i === 0) $('a.turn-previous').attr("style", "display: none;").html()
if (i === (totalPages - 1)) $('a.turn-next').attr("style", "display: none;").html()
htmlOutput = $.html()
}
fs.writeFile('site/blog/' + pagePath, htmlOutput, function (err) {
// need to make this outputDir + /blog/
fs.writeFile(opts.output + '/blog/' + pagePath, htmlOutput, function (err) {
if (err) throw err
})
}
})
})

@@ -65,7 +79,7 @@ }

if (currentPage === 1) return 'index.html'
else return 'page/' + (currentPage - 1)
else return (currentPage - 1) + '.html'
}
function nextURL(currentPage){
return currentPage + 1
return (currentPage + 1) + '.html'
}

@@ -76,7 +90,7 @@

if (currentPage === 0) pagePath = 'index.html'
else pagePath = 'page/' + (currentPage) + '.html'
else pagePath = currentPage + '.html'
return pagePath
}
function separatePosts (filesAndContent) {
function separatePosts(filesAndContent) {
var posts = []

@@ -88,3 +102,4 @@ filesAndContent.forEach(function(item) {

// sort by date
posts.sort(function(a,b) {
var sorted = posts
sorted.sort(function(a,b) {
a = a.content.date

@@ -94,3 +109,3 @@ b = b.content.date

})
return posts.reverse()
return sorted
}

@@ -100,17 +115,18 @@

function onlyContent(posts) {
var onlypostcontent = []
posts.forEach(function(post) {
onlypostcontent.push(post.content.content)
})
return onlypostcontent
}
// function onlyContent(posts) {
// var onlypostcontent = []
// posts.forEach(function(post) {
// onlypostcontent.push(post.content.content)
// })
// return onlypostcontent
// }
function sortPosts(posts) {
posts.sort(function(a,b) {
a = new Date(a.date)
b = new Date(b.date)
return (a === b) ? 0 : a > b ? -1 : 1;
})
}
// function sortPosts(posts) {
// posts.sort(function(a,b) {
// // a = new Date(a.date)
// // b = new Date(b.date)
// // return (a === b) ? 0 : a > b ? -1 : 1;
// return a.content.date - b.content.date
// })
// }

@@ -117,0 +133,0 @@ // notes:

@@ -5,9 +5,21 @@ var marked = require('marked')

var result = extractMetaMatter(contents)
result.content = marked(contents.toString('utf-8'));
var content = removeHeaders(contents)
result.content = marked(content.toString('utf-8'))
return result
}
function getMetaLines(contents) {
var lines = contents.toString('utf-8').split('\n')
var end = 4
for (var i = 0; i < 4; i++) {
if (lines[i] === "") {
end = i
}
}
return lines.slice(0, end)
}
function extractMetaMatter(contents) {
var lines = contents.toString('utf-8').split('\n')
var meta = lines.slice(0, 4)
var meta = getMetaLines(contents)
.filter(onlyHeaders)

@@ -31,1 +43,21 @@ .map(stripHeaders)

}
function removeHeaders(contents) {
var lines = contents.toString('utf-8').split('\n')
// the headers are the first lines of the
// document with # until the first ''
// so see where that '' occurs to know
// when to cut for the body
var cut = 4
for (var i = 0; i < 4; i++) {
if (lines[i] === "") {
cut = i
}
}
var headers = lines.filter(onlyHeaders)
// console.log(lines, cut, lines.length)
// console.log(lines.splice(cut, lines.length).join('\n'))
return lines.splice(cut, lines.length).join('\n')
}
var path = require('path')
var http = require('http')
var ecstatic = require('ecstatic')
var server = http.createServer(require('ecstatic')(path.join(process.cwd(), 'site')))
var server = http.createServer(require('ecstatic')(path.join(process.cwd(), '')))
// var server = http.createServer(require('ecstatic')(path.join(process.cwd(), 'site')))
server.listen(0)
server.listen(5567)

@@ -8,0 +9,0 @@ server.on('listening', function () {

{
"name": "balrog",
"version": "1.0.0",
"version": "1.0.1",
"description": "static site generator",

@@ -24,3 +24,3 @@ "main": ".bin/balrog",

"clean": "rm -rf site/*",
"test": "tape test/*.js"
"test": "node test/*.js"
},

@@ -34,3 +34,3 @@ "bin": {

"moment": "1.7.2",
"marked": "~0.2.9",
"marked": "~0.3.2",
"handlebars": "~1.0.12",

@@ -37,0 +37,0 @@ "mkdirp": "~0.3.5",

@@ -1,10 +0,8 @@

_this is the new readme, it's in progress. it's not all accurate. don't try and follow it :)_
# Hi!
_Disclaimer: One, this documentation is out of date, two, I've made this for my own purposes so it's very suited to that, it likely won't work, out of the box, just like you want it to, or be very adaptable. But! Have a look if ya want, fork and change it all up!_
![balrog](https://raw2.github.com/jlord/balrog/master/balrog.png)
---
_WIP_
A static site generator with these goals:

@@ -23,4 +21,4 @@

|_BlogFolder
|_partials (required)
-pagination.html (required)
|_partials (optional)
-pagination.html (optional)
-header.html

@@ -91,3 +89,3 @@ -footer.html

1. Set up file structure as described above
- You can copy the base files from the [template branch](#)
- You can copy the base files from the [template branch](https://github.com/jlord/balrog/tree/template)
2. Create `config.JSON`

@@ -94,0 +92,0 @@ 3. Make sure you include and use the following as described:

Sorry, the diff of this file is not supported yet