-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.coffee
175 lines (166 loc) · 7.36 KB
/
build.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
fs = require "fs"
path = require 'path'
glob = require 'glob'
async = require 'async'
rimraf = require 'rimraf'
marked = require 'marked'
fse = require 'fs-extra'
ck = require 'coffeekup'
_ = require 'lodash'
cheerio = require 'cheerio'
{exec} = require 'child_process'
OUTDIR = 'dist'
indextpl = ->
doctype 5
html lang: "en", ->
head ->
meta charset: "utf-8"
title "But Professor‽"
link href: "bower_components/bootstrap/dist/css/bootstrap.min.css", rel: "stylesheet"
link href: "static/blog.css", rel: "stylesheet"
script """
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-71639036-1', 'auto');
ga('send', 'pageview');
"""
body ->
div ".container", ->
div ".blog-header", ->
h1 ".blog-title", ->
a href: 'index.html', "But Professor‽"
p ".lead.blog-description", "Some random deep thoughts from when “it’s compiling”"
div ".row", ->
div ".col-sm-8.blog-main", ->
for post in @posts
div ".blog-post", ->
div post.compiled
div ".addthis_sharing_toolbox", ''
a href: post.fnew, '[permalink]'
hr()
div ".col-sm-3.col-sm-offset-1.blog-sidebar", ->
div ".sidebar-module.sidebar-module-inset", ->
h4 "About"
p "A blog on programming as art, critical thinking and things like that"
script type: "text/javascript", src: "//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56828401947111a4", async: "async"
script src: "bower_components/jquery/dist/jquery.min.js"
script src: "bower_components/bootstrap/dist/js/bootstrap.min.js"
posttpl = ->
doctype 5
html lang: "en", ->
head ->
meta charset: "utf-8"
title "But Professor‽"
link href: "bower_components/bootstrap/dist/css/bootstrap.min.css", rel: "stylesheet"
link href: "static/blog.css", rel: "stylesheet"
script """
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-71639036-1', 'auto');
ga('send', 'pageview');
"""
body ->
div ".container", ->
div ".blog-header", ->
h1 ".blog-title", ->
a href: 'index.html', "But Professor‽"
p ".lead.blog-description", "Some random deep thoughts from when “it’s compiling”"
div ".row", ->
div ".col-sm-8.blog-main", ->
div ".blog-post", ->
div @post.compiled
a href: @post.fnew, '[permalink]'
div ".addthis_sharing_toolbox", ''
hr()
div "#disqus_thread", ''
script """
/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables
*/
/*
var disqus_config = function () {
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = """ + @post.fnew + """; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
*/
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://butprofessor.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
"""
noscript ->
text "Please enable JavaScript to view the "
a href: "https://disqus.com/?ref_noscript", rel: "nofollow", "comments powered by Disqus."
script type: "text/javascript", ->
"""google_ad_client = "ca-pub-5489197102815138";
google_ad_slot = "1331359202";
google_ad_width = 728;
google_ad_height = 90;"""
script type: "text/javascript", src:"//pagead2.googlesyndication.com/pagead/show_ads.js"
# nav ->
# ul ".pager", ->
# li ->
# a href: "#", "Previous"
# li ->
# a href: "#", "Next"
div ".col-sm-3.col-sm-offset-1.blog-sidebar", ->
div ".sidebar-module.sidebar-module-inset", ->
h4 "About"
p "A blog on programming as art, critical thinking and things like that"
script type: "text/javascript", src: "//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-56828401947111a4", async: "async"
script src: "bower_components/jquery/dist/jquery.min.js"
script src: "bower_components/bootstrap/dist/js/bootstrap.min.js"
doBuild = (odir = OUTDIR, cb) ->
async.auto {
rmdir: (cb) ->
rimraf odir, {disableGlob: false}, (err) -> cb null
mkdir: ['rmdir', (cb) ->
fse.mkdirs odir, (err) ->
cb err
]
bower: ['mkdir', (cb) ->
exec 'bower install', (err, so, se) ->
cb err, {so, se}
]
bowermover: ['bower', (cb) ->
fse.copy 'bower_components', path.join(odir, 'bower_components'), {clobber: true}, (err) -> cb err
]
staticmover: ['mkdir', (cb) ->
fse.copy 'static', path.join(odir, 'static'), {clobber: true}, (err) -> cb err
]
glob: (cb) ->
glob 'pages/*', cb
convert: ['mkdir', 'glob', (cb, res) ->
async.map res.glob.sort().reverse(), ((fn, cb) ->
fs.readFile fn, (err, content) ->
ch = cheerio.load marked(content.toString())
fnew = path.parse(fn).name + '.html'
ch('h2').first().replaceWith('<h2><a href="' + fnew + '">' + ch('h2').first().text() + '</a></h2>')
ret = {compiled: ch.html(), fnew}
fs.writeFile path.join(odir, fnew), ck.render(posttpl, {post: ret, format: true}), (err) ->
cb err, ret
), (err, posts) ->
cb err, {posts}
]
index: ['convert', (cb, res) ->
fs.writeFile path.join(odir, "index.html"), ck.render(indextpl, {posts: res.convert.posts, format: true}), (error) ->
cb error
]
sitemap: ['convert', (cb, res) ->
fs.writeFile path.join(odir, "sitemap.txt"), ('http://bessbd.github.io/butprofessor/' + fn for fn in ['index.html'].concat(post.fnew for post in res.convert.posts)).join('\n'), (error) ->
cb error
]
}, (err, results) ->
console.log {err, results}
module.exports = {doBuild}
if require.main is module
od = process.argv[2] || OUTDIR
doBuild od, ->
console.log "done"