fix markdown, hack in style assets

This commit is contained in:
AJ ONeal 2015-01-09 04:44:11 +00:00
parent 062a7be3b1
commit c995197c0b
5 changed files with 61 additions and 37 deletions

View File

@ -33,10 +33,10 @@
"bluebird": "~2.5.2", "bluebird": "~2.5.2",
"rsvp": "~3.0.16", "rsvp": "~3.0.16",
"escape-string-regexp": "~1.0.2", "escape-string-regexp": "~1.0.2",
"marked": "~0.3.2",
"js-yaml": "~3.2.5", "js-yaml": "~3.2.5",
"path": "~3.46.1", "path": "~3.46.1",
"forEachAsync": "~5.0.5", "forEachAsync": "~5.0.5",
"node-uuid": "~1.4.2" "node-uuid": "~1.4.2",
"markdown-it": "~3.0.2"
} }
} }

View File

@ -6,7 +6,7 @@
var PromiseA = exports.Promise || require('bluebird').Promise var PromiseA = exports.Promise || require('bluebird').Promise
, path = exports.path || require('path') , path = exports.path || require('path')
, Mustache = exports.Mustache || require('mustache') , Mustache = exports.Mustache || require('mustache')
, marked = exports.marked || require('marked') , marked = (exports.markdownit || require('markdown-it'))({ html: true, linkify: true })
, forEachAsync = exports.forEachAsync || require('foreachasync').forEachAsync , forEachAsync = exports.forEachAsync || require('foreachasync').forEachAsync
//, sha1sum = exports.sha1sum || require('./lib/deardesi-node').sha1sum //, sha1sum = exports.sha1sum || require('./lib/deardesi-node').sha1sum
, frontmatter = exports.Frontmatter || require('./lib/frontmatter').Frontmatter , frontmatter = exports.Frontmatter || require('./lib/frontmatter').Frontmatter
@ -422,26 +422,27 @@
} }
function normalizeContentEntity(entity) { function normalizeContentEntity(entity) {
// The root index is the one exception entity.ext = path.extname(entity.path);
if (/^\/?index$/.test(entity.yml.permalink)) { entity.url = desi.urls.url + path.join(desi.urls.base_path, entity.yml.permalink);
console.info('found index', entity); entity.canonical_url = desi.urls.url + path.join(desi.urls.base_path, entity.yml.permalink);
entity.yml.permalink = ''; entity.relative_url = path.join(desi.urls.base_path, entity.yml.permalink);
}
entity.url = desi.urls.url + path.join(desi.urls.base_path, entity.yml.permalink, 'index.html');
entity.cananical_url = desi.urls.url + path.join(desi.urls.base_path, entity.yml.permalink, 'index.html');
entity.relative_url = path.join(desi.urls.base_path, entity.yml.permalink, 'index.html');
entity.published_at = fromLocaleDate(entity.yml.date); entity.published_at = fromLocaleDate(entity.yml.date);
entity.year = entity.published_at.year; entity.year = entity.published_at.year;
entity.month = entity.published_at.month; entity.month = entity.published_at.month;
entity.day = entity.published_at.day; entity.day = entity.published_at.day;
entity.hour = entity.published_at.hour; entity.hour = entity.published_at.hour;
entity.twelve_hour = entity.published_at.twelve_hour; entity.twelve_hour = entity.published_at.twelve_hour;
entity.meridian = entity.published_at.meridian; entity.meridian = entity.published_at.meridian;
entity.minute = entity.published_at.minute; entity.minute = entity.published_at.minute;
entity.title = entity.yml.title; entity.title = entity.yml.title;
// let's just agree that that's too far // let's just agree that that's too far
//entity.second = entity.published_at.second; //entity.second = entity.published_at.second;
// The root index is the one exception
if (/^\/?index$/.test(entity.yml.permalink)) {
entity.yml.permalink = '';
console.info('found index', entity);
}
} }
function byDate(a, b) { function byDate(a, b) {
@ -547,11 +548,18 @@
function compileScriptEntity(entity, i, arr) { function compileScriptEntity(entity, i, arr) {
} }
*/ */
desi.assets = [];
function compileThemeEntity(entity, i, arr) { function compileThemeEntity(entity, i, arr) {
console.log("compiling " + (i + 1) + "/" + arr.length + " " + (entity.path || entity.name)); console.log("compiling " + (i + 1) + "/" + arr.length + " " + (entity.path || entity.name));
// TODO less / sass / etc // TODO less / sass / etc
compiled.push({ contents: entity.body || entity.contents, path: path.join(desi.config.compiled_path, 'themes', entity.path) }); compiled.push({ contents: entity.body || entity.contents, path: path.join(desi.config.compiled_path, 'themes', entity.path) });
if (/stylesheets.*\.css/.test(entity.path) && (!/google/.test(entity.path) || /obsid/.test(entity.path))) {
desi.assets.push(
'<link href="' + entity.path + '" type="text/css" rel="stylesheet" media="all">'
);
}
} }
console.log(desi.navigation);
function compileContentEntity(entity, i, arr) { function compileContentEntity(entity, i, arr) {
console.log("compiling " + (i + 1) + "/" + arr.length + " " + (entity.path || entity.name)); console.log("compiling " + (i + 1) + "/" + arr.length + " " + (entity.path || entity.name));
@ -572,29 +580,44 @@
, categories: [] // *all* categories in all collections , categories: [] // *all* categories in all collections
, tags: [] // *all* tags in all collections , tags: [] // *all* tags in all collections
, site: num2str(desi.site || {}) , site: num2str(desi.site || {})
, url: entity.cananical_url , url: entity.canonical_url
, canonical_url: entity.cananical_url , canonical_url: entity.canonical_url
, relative_url: entity.relative_url , relative_url: entity.relative_url
, urls: desi.urls , urls: desi.urls
, previous: arr[i - 1] , previous: arr[i - 1]
, next: arr[i + 1] , next: arr[i + 1]
, posts: { collated: desi.collated } , posts: { collated: desi.collated }
// TODO concat theme, widget, and site assets
, assets: desi.assets.join('\n')
}; };
//console.log('rel:', view.relative_url);
view.site.author = desi.data.author; view.site.author = desi.data.author;
view.site['navigation?to_pages'] = desi.navigation.slice(0); view.site.navigation = JSON.parse(JSON.stringify(desi.navigation));
view.site.navigation.forEach(function (nav) {
if (nav.href === view.relative_url) {
nav.active = true;
}
});
// backwards compat
view.site['navigation?to_pages'] = view.site.navigation;
layers.forEach(function (parent) { layers.forEach(function (current) {
// TODO meta.layout // TODO meta.layout
var body = (parent.body || parent.contents || '').trim() var body = (current.body || current.contents || '').trim()
, html , html
; ;
parent.path = parent.path || entity.relativePath + '/' + entity.name; current.path = current.path || entity.relativePath + '/' + entity.name;
if (/\.(html|htm)$/.test(parent.path)) { if (/\.(html|htm)$/.test(current.path)) {
html = body; html = body;
} else if (/\.(md|markdown|mdown|mkdn|mkd|mdwn|mdtxt|mdtext)$/.test(parent.path)) { } else if (/\.(md|markdown|mdown|mkdn|mkd|mdwn|mdtxt|mdtext)$/.test(current.ext)) {
html = marked(body); html = marked.render(body)
//.replace('&quot;', '"')
//.replace('&#39;', "'")
//.replace('&#x2F;', '/')
;
} else { } else {
console.error('unknown parser for ' + (entity.path)); console.error('unknown parser for ' + (entity.path));
} }
@ -633,12 +656,13 @@
}); });
} }
console.info('[first] compiling theme assets');
desi.content.themes.filter(function (f) { return !/\blayouts\b/.test(f.path); }).forEach(compileThemeEntity);
console.info('compiling root pages'); console.info('compiling root pages');
desi.content.root.forEach(compileContentEntity); desi.content.root.forEach(compileContentEntity);
console.info('compiling article pages'); console.info('compiling article pages');
desi.content.collections.forEach(compileContentEntity); desi.content.collections.forEach(compileContentEntity);
console.info('compiling theme assets');
desi.content.themes.filter(function (f) { return !/\blayouts\b/.test(f.path); }).forEach(compileThemeEntity);
desi.compiled = compiled; desi.compiled = compiled;
return desi; return desi;

View File

@ -5,7 +5,7 @@
<!-- Deps --> <!-- Deps -->
<script src="./bower_components/bluebird/js/browser/bluebird.js"></script> <script src="./bower_components/bluebird/js/browser/bluebird.js"></script>
<script src="./bower_components/mustache/mustache.js"></script> <script src="./bower_components/mustache/mustache.js"></script>
<script src="./bower_components/marked/lib/marked.js"></script> <script src="./bower_components/markdown-it/dist/markdown-it.js"></script>
<script src="./bower_components/js-yaml/dist/js-yaml.js"></script> <script src="./bower_components/js-yaml/dist/js-yaml.js"></script>
<script src="./bower_components/path/path.js"></script> <script src="./bower_components/path/path.js"></script>
<script src="./bower_components/node-uuid/uuid.js"></script> <script src="./bower_components/node-uuid/uuid.js"></script>

View File

@ -40,7 +40,7 @@
"foreachasync": "^5.0.5", "foreachasync": "^5.0.5",
"json2yaml": "^1.0.3", "json2yaml": "^1.0.3",
"markdown": "^0.5.0", "markdown": "^0.5.0",
"marked": "^0.3.2", "markdown-it": "^3.0.2",
"mkdirp": "^0.5.0", "mkdirp": "^0.5.0",
"mustache": "^1.0.0", "mustache": "^1.0.0",
"node-uuid": "^1.4.2", "node-uuid": "^1.4.2",

View File

@ -1,8 +1,8 @@
--- ---
pages_list: | pages_list: >
<li {{# active }}class="active"{{/ active }} <li{{# active }} class="active"{{/ active }}><a{{# active }} class="active"{{/ active }}
><a href="{{{ path }}}" {{# active }}class="active"{{/ active }}>{{ title }}</a href="{{{ path }}}"
></li> >{{ title }}</a></li>
# [{ 'year': year, # [{ 'year': year,
# 'months' : [{ 'month' : month, # 'months' : [{ 'month' : month,