diff --git a/bower.json b/bower.json index 613762d..83c745c 100644 --- a/bower.json +++ b/bower.json @@ -33,10 +33,10 @@ "bluebird": "~2.5.2", "rsvp": "~3.0.16", "escape-string-regexp": "~1.0.2", - "marked": "~0.3.2", "js-yaml": "~3.2.5", "path": "~3.46.1", "forEachAsync": "~5.0.5", - "node-uuid": "~1.4.2" + "node-uuid": "~1.4.2", + "markdown-it": "~3.0.2" } } diff --git a/deardesi.js b/deardesi.js index 4f09afe..122d7be 100644 --- a/deardesi.js +++ b/deardesi.js @@ -6,7 +6,7 @@ var PromiseA = exports.Promise || require('bluebird').Promise , path = exports.path || require('path') , 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 //, sha1sum = exports.sha1sum || require('./lib/deardesi-node').sha1sum , frontmatter = exports.Frontmatter || require('./lib/frontmatter').Frontmatter @@ -422,26 +422,27 @@ } function normalizeContentEntity(entity) { - // The root index is the one exception - if (/^\/?index$/.test(entity.yml.permalink)) { - console.info('found index', entity); - 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.ext = path.extname(entity.path); + entity.url = desi.urls.url + path.join(desi.urls.base_path, entity.yml.permalink); + entity.canonical_url = desi.urls.url + path.join(desi.urls.base_path, entity.yml.permalink); + entity.relative_url = path.join(desi.urls.base_path, entity.yml.permalink); entity.published_at = fromLocaleDate(entity.yml.date); - entity.year = entity.published_at.year; - entity.month = entity.published_at.month; - entity.day = entity.published_at.day; - entity.hour = entity.published_at.hour; - entity.twelve_hour = entity.published_at.twelve_hour; - entity.meridian = entity.published_at.meridian; - entity.minute = entity.published_at.minute; - entity.title = entity.yml.title; + entity.year = entity.published_at.year; + entity.month = entity.published_at.month; + entity.day = entity.published_at.day; + entity.hour = entity.published_at.hour; + entity.twelve_hour = entity.published_at.twelve_hour; + entity.meridian = entity.published_at.meridian; + entity.minute = entity.published_at.minute; + entity.title = entity.yml.title; // let's just agree that that's too far //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) { @@ -547,11 +548,18 @@ function compileScriptEntity(entity, i, arr) { } */ + desi.assets = []; function compileThemeEntity(entity, i, arr) { console.log("compiling " + (i + 1) + "/" + arr.length + " " + (entity.path || entity.name)); // TODO less / sass / etc 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( + '' + ); + } } + console.log(desi.navigation); function compileContentEntity(entity, i, arr) { console.log("compiling " + (i + 1) + "/" + arr.length + " " + (entity.path || entity.name)); @@ -572,29 +580,44 @@ , categories: [] // *all* categories in all collections , tags: [] // *all* tags in all collections , site: num2str(desi.site || {}) - , url: entity.cananical_url - , canonical_url: entity.cananical_url + , url: entity.canonical_url + , canonical_url: entity.canonical_url , relative_url: entity.relative_url , urls: desi.urls , previous: arr[i - 1] , next: arr[i + 1] , 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['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 - var body = (parent.body || parent.contents || '').trim() + var body = (current.body || current.contents || '').trim() , 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; - } else if (/\.(md|markdown|mdown|mkdn|mkd|mdwn|mdtxt|mdtext)$/.test(parent.path)) { - html = marked(body); + } else if (/\.(md|markdown|mdown|mkdn|mkd|mdwn|mdtxt|mdtext)$/.test(current.ext)) { + html = marked.render(body) + //.replace('"', '"') + //.replace(''', "'") + //.replace('/', '/') + ; } else { 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'); desi.content.root.forEach(compileContentEntity); console.info('compiling article pages'); 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; return desi; diff --git a/index.html b/index.html index a5533f2..4e11fca 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ - + diff --git a/package.json b/package.json index 729d127..cff9f74 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "foreachasync": "^5.0.5", "json2yaml": "^1.0.3", "markdown": "^0.5.0", - "marked": "^0.3.2", + "markdown-it": "^3.0.2", "mkdirp": "^0.5.0", "mustache": "^1.0.0", "node-uuid": "^1.4.2", diff --git a/partials.yml b/partials.yml index ee58354..924c990 100644 --- a/partials.yml +++ b/partials.yml @@ -1,8 +1,8 @@ --- -pages_list: | -
  • {{ title }}
  • +pages_list: > + {{ title }} # [{ 'year': year, # 'months' : [{ 'month' : month,