dual compat in ruhoh datamapper, minor cleanup
This commit is contained in:
		
							parent
							
								
									2cb28f9e0e
								
							
						
					
					
						commit
						aba73978b6
					
				
							
								
								
									
										95
									
								
								desirae.js
									
									
									
									
									
								
							
							
						
						
									
										95
									
								
								desirae.js
									
									
									
									
									
								
							| @ -178,7 +178,12 @@ | |||||||
|     return byDirty; |     return byDirty; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   function getLayout(desi, themename, layout, arr) { |   function getLayout(desi, themename, layoutname, arr, i) { | ||||||
|  |     if (i > (desi.config.max_layouth_depth || 10)) { | ||||||
|  |       console.error('desi.config.yml:max_layouth_depth if your layouts intentionally nest more than ' + i + ' levels deep'); | ||||||
|  |       throw new Error("Possible circular dependency in theme '" + themename + "', layout '" + layoutname + "'"); | ||||||
|  |     } | ||||||
|  |     i = i || 0; | ||||||
|     // TODO meta.layout for each entity
 |     // TODO meta.layout for each entity
 | ||||||
|     arr = arr || []; |     arr = arr || []; | ||||||
| 
 | 
 | ||||||
| @ -190,14 +195,20 @@ | |||||||
|     if (!themename) { |     if (!themename) { | ||||||
|       themename = desi.config.themes.default; |       themename = desi.config.themes.default; | ||||||
|     } |     } | ||||||
|     if (!layout) { | 
 | ||||||
|       // TODO make configurable
 |     // defaults to ruhoh-twitter defaults
 | ||||||
|       layout = 'posts.html'; |     if ('__page__' === layoutname) { | ||||||
|  |       layoutname = desi.config.themes[themename].pageLayout || 'page'; | ||||||
|  |     } else if ('__post__' === layoutname) { | ||||||
|  |       layoutname = desi.config.themes[themename].postLayout || 'post'; | ||||||
|  |     } else if (!layoutname) { | ||||||
|  |       // TODO assign __post__ in a previous step and do away with this case
 | ||||||
|  |       layoutname = desi.config.themes[themename].postLayout || 'post'; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     // THEME PREFIX
 |     // THEME PREFIX
 | ||||||
|     themepath = path.join(THEME_PREFIX, themename, layoutdir, layout); |     themepath = path.join(THEME_PREFIX, themename, layoutdir, layoutname); | ||||||
| 
 | 
 | ||||||
|     desi.content.themes.some(function (theme) { |     desi.content.themes.some(function (theme) { | ||||||
|       // TODO what if it isn't html?
 |       // TODO what if it isn't html?
 | ||||||
| @ -215,12 +226,16 @@ | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // TODO handle possible circular dep condition page -> post -> page
 |     // TODO handle possible circular dep condition page -> post -> page
 | ||||||
|     if (file.yml && file.yml.layout) { |     if (!file.yml || !file.yml.layout) { | ||||||
|       return getLayout(desi, themename, file.yml.layout, arr); |       // return the chain page -> posts -> default -> ruhoh-twitter
 | ||||||
|     } else { |  | ||||||
|       // return the chain page -> posts -> default -> bootstrap-2
 |  | ||||||
|       return arr; |       return arr; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     if (!file.yml || !file.yml.layout) { | ||||||
|  |       return arr; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return getLayout(desi, themename, file.yml.layout, arr, i + 1); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   function clone(obj) { |   function clone(obj) { | ||||||
| @ -251,8 +266,6 @@ | |||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   Desi.init = function (desi, env) { |   Desi.init = function (desi, env) { | ||||||
|     console.log(''); |  | ||||||
|     console.log(''); |  | ||||||
|     console.info('getting config, data, caches...'); |     console.info('getting config, data, caches...'); | ||||||
| 
 | 
 | ||||||
|     if (!exports.window) { |     if (!exports.window) { | ||||||
| @ -266,11 +279,7 @@ | |||||||
|         ;  |         ;  | ||||||
| 
 | 
 | ||||||
|       console.info('loaded config, data, caches, partials'); |       console.info('loaded config, data, caches, partials'); | ||||||
|       console.log({ |       /* console.log({ config:   arr.config , site:     arr.site , authors:  arr.authors }); */ | ||||||
|         config:   arr.config |  | ||||||
|       , site:     arr.site |  | ||||||
|       , authors:  arr.authors |  | ||||||
|       }); |  | ||||||
| 
 | 
 | ||||||
|       //desi.blogdir = blogdir;
 |       //desi.blogdir = blogdir;
 | ||||||
|       desi.originals = {}; |       desi.originals = {}; | ||||||
| @ -288,14 +297,14 @@ | |||||||
|         desi.config.collections = { 'posts': {} }; |         desi.config.collections = { 'posts': {} }; | ||||||
|       } |       } | ||||||
|       if ('object' !== typeof desi.config.themes || !Object.keys(desi.config.themes).length) { |       if ('object' !== typeof desi.config.themes || !Object.keys(desi.config.themes).length) { | ||||||
|         desi.config.themes = { 'default': 'bootstrap-2', 'bootstrap-2': {} }; |         desi.config.themes = { 'default': 'ruhoh-twitter', 'ruhoh-twitter': {} }; | ||||||
|       } |       } | ||||||
|       if ('object' !== typeof desi.config.assets || !Object.keys(desi.config.assets).length) { |       if ('object' !== typeof desi.config.assets || !Object.keys(desi.config.assets).length) { | ||||||
|         desi.config.assets = { 'media': {} }; |         desi.config.assets = { 'media': {} }; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (!Array.isArray(desi.site.navigation) || !desi.site.navigation.length) { |       if (!Array.isArray(desi.site.navigation) || !desi.site.navigation.length) { | ||||||
|         desi.site.navigation = ['archive']; |         desi.site.navigation = []; // ['archive'];
 | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       var collectionnames = Object.keys(desi.config.collections) |       var collectionnames = Object.keys(desi.config.collections) | ||||||
| @ -335,13 +344,7 @@ | |||||||
|       ]); |       ]); | ||||||
|     }).then(function (things) { |     }).then(function (things) { | ||||||
|       console.info('loaded theme meta, root meta, collection meta'); |       console.info('loaded theme meta, root meta, collection meta'); | ||||||
|       console.log({ |       /* console.log({ theme:      things[0] , root:       things[1] , collection: things[2] , asset:      things[3] , cache:      things[4] }); */ | ||||||
|         theme:      things[0] |  | ||||||
|       , root:       things[1] |  | ||||||
|       , collection: things[2] |  | ||||||
|       , asset:      things[3] |  | ||||||
|       , cache:      things[4] |  | ||||||
|       }); |  | ||||||
| 
 | 
 | ||||||
|       function noErrors(map) { |       function noErrors(map) { | ||||||
|         Object.keys(map).forEach(function (path) { |         Object.keys(map).forEach(function (path) { | ||||||
| @ -500,6 +503,13 @@ | |||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   Desi.getNav = function (desi) { |   Desi.getNav = function (desi) { | ||||||
|  |     var alwaysAdd = true | ||||||
|  |       ; | ||||||
|  | 
 | ||||||
|  |     if (desi.site.navigation.length) { | ||||||
|  |       alwaysAdd = false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     // TODO add missing metadata and resave file
 |     // TODO add missing metadata and resave file
 | ||||||
|     desi.navigation = []; |     desi.navigation = []; | ||||||
| 
 | 
 | ||||||
| @ -509,10 +519,17 @@ | |||||||
|         , nindex |         , nindex | ||||||
|         ; |         ; | ||||||
| 
 | 
 | ||||||
|  |       console.log('page.path', page.path); | ||||||
|  |       if (alwaysAdd && /^(_root\/)index(\.\w+)$/i.test(page.path)) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|       //if (-1 === desi.data.navigation.indexOf(name) && 'index' !== name)
 |       //if (-1 === desi.data.navigation.indexOf(name) && 'index' !== name)
 | ||||||
|       nindex = (desi.site.navigation).indexOf(name); |       nindex = (desi.site.navigation).indexOf(name); | ||||||
|       if (-1 === nindex) { |       if (!alwaysAdd && -1 === nindex) { | ||||||
|         return; |         return; | ||||||
|  |       } else { | ||||||
|  |         nindex = desi.navigation.length; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       desi.navigation[nindex] = { |       desi.navigation[nindex] = { | ||||||
| @ -534,7 +551,7 @@ | |||||||
|     desi.content.root.forEach(function (page) { |     desi.content.root.forEach(function (page) { | ||||||
|       page.yml = page.yml || {}; |       page.yml = page.yml || {}; | ||||||
|       // TODO make default layout configurable
 |       // TODO make default layout configurable
 | ||||||
|       page.yml.layout = page.yml.layout || '_root'; |       page.yml.layout = page.yml.layout || '__page__'; | ||||||
| 
 | 
 | ||||||
|       if (!page.relativePath) { |       if (!page.relativePath) { | ||||||
|         page.relativePath = path.dirname(page.path); |         page.relativePath = path.dirname(page.path); | ||||||
| @ -748,6 +765,12 @@ | |||||||
|     obj.desi = obj; |     obj.desi = obj; | ||||||
|     return obj; |     return obj; | ||||||
|   }); |   }); | ||||||
|  |   /* | ||||||
|  |   Desi.registerDataMapper('ruhoh@twitter', function (view) { | ||||||
|  |   }); | ||||||
|  |   Desi.registerDataMapper('ruhoh@bootstrap-2', function (view) { | ||||||
|  |   }); | ||||||
|  |   */ | ||||||
|   Desi.registerDataMapper('ruhoh@2.6', function (view) { |   Desi.registerDataMapper('ruhoh@2.6', function (view) { | ||||||
|     var newview |     var newview | ||||||
|       ; |       ; | ||||||
| @ -755,8 +778,9 @@ | |||||||
|     newview = { |     newview = { | ||||||
|       content: view.contents |       content: view.contents | ||||||
|     , page: { |     , page: { | ||||||
|         title: view.entity.yml.title || view.site.title |         title: view.entity.yml.title || view.site.title     // in rt
 | ||||||
|       , tagline: view.entity.yml.tagline |       , tagline: view.entity.yml.tagline                    // in rt
 | ||||||
|  |       , description: view.entity.yml.description            // in rt
 | ||||||
|       , content: view.contents |       , content: view.contents | ||||||
|       , youtube: view.entity.yml.youtube |       , youtube: view.entity.yml.youtube | ||||||
|       , tags: view.entity.yml.tags |       , tags: view.entity.yml.tags | ||||||
| @ -768,6 +792,11 @@ | |||||||
|       , date: view.entity.year + '-' + view.entity.month + '-' + view.entity.day |       , date: view.entity.year + '-' + view.entity.month + '-' + view.entity.day | ||||||
|       // TODO , url: view.entities.
 |       // TODO , url: view.entities.
 | ||||||
|       } |       } | ||||||
|  |     , 'page?previous': view.entities[view.entity_index - 1] // ruhoh-twitter only
 | ||||||
|  |         // should contain { url: ..., title: ... }
 | ||||||
|  |     , 'page?next': view.entities[view.entity_index + 1]     // ruhoh-twitter only
 | ||||||
|  |     , 'page.categories?to_categories': []                   // ruhoh-twitter only
 | ||||||
|  |     , 'page.tags?to_tags': []                               // ruhoh-twitter only
 | ||||||
|     , posts: { collated: view.desi.collated } |     , posts: { collated: view.desi.collated } | ||||||
|     , urls: { |     , urls: { | ||||||
|         base_url: view.env.base_url |         base_url: view.env.base_url | ||||||
| @ -783,7 +812,7 @@ | |||||||
|       , title: view.site.title |       , title: view.site.title | ||||||
|       } |       } | ||||||
|     , styles: view.desi.styles.join('\n') |     , styles: view.desi.styles.join('\n') | ||||||
|     , assets: view.desi.styles.join('\n') |     , assets: view.desi.styles.join('\n') // ruhoh-twitter
 | ||||||
|     , widgets: { |     , widgets: { | ||||||
|         comments: view.site.disqus_shortname && |         comments: view.site.disqus_shortname && | ||||||
|           Mustache.render(view.desi.partials.disqus, { disqus: { |           Mustache.render(view.desi.partials.disqus, { disqus: { | ||||||
| @ -805,11 +834,15 @@ | |||||||
|       } |       } | ||||||
|     , site: { |     , site: { | ||||||
|         navigation: view.navigation |         navigation: view.navigation | ||||||
|  |       , title: view.site.title                              // ruhoh-twitter only
 | ||||||
|  |       , author: {                                           // ruhoh-twitter only
 | ||||||
|  |           name: view.author.name                            // ruhoh-twitter only
 | ||||||
|  |         } | ||||||
|       } |       } | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     // backwards compat
 |     // backwards compat
 | ||||||
|     newview.site['navigation?to_pages'] = newview.site.navigation; |     newview.site['navigation?to_pages'] = newview.site.navigation;  // ruhoh-twitter only
 | ||||||
|     newview.site['navigation?to__root'] = newview.site.navigation; |     newview.site['navigation?to__root'] = newview.site.navigation; | ||||||
|     newview.data.navigation = view.site.navigation; |     newview.data.navigation = view.site.navigation; | ||||||
|     newview.data['navigation?to_pages'] = newview.site.navigation; |     newview.data['navigation?to_pages'] = newview.site.navigation; | ||||||
|  | |||||||
| @ -186,7 +186,6 @@ | |||||||
| 
 | 
 | ||||||
|     Desi.fsapi = fsapi = Desi.fsapi || {}; |     Desi.fsapi = fsapi = Desi.fsapi || {}; | ||||||
|     fsapi.getMeta = function (collections, opts) { |     fsapi.getMeta = function (collections, opts) { | ||||||
|       console.log('dm sub 0'); |  | ||||||
|       opts = opts || {}; |       opts = opts || {}; | ||||||
| 
 | 
 | ||||||
|       var extensions = '' |       var extensions = '' | ||||||
| @ -208,14 +207,11 @@ | |||||||
|         sha1sum = '&sha1sum=false'; |         sha1sum = '&sha1sum=false'; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       console.log('dm sub 1'); |  | ||||||
|       return request.post('/api/fs/walk?_method=GET' + dotfiles + extensions + contents + sha1sum, { |       return request.post('/api/fs/walk?_method=GET' + dotfiles + extensions + contents + sha1sum, { | ||||||
|         dirs: collections |         dirs: collections | ||||||
|       }).then(function (resp) { |       }).then(function (resp) { | ||||||
|         console.log('dm sub 2'); |  | ||||||
|         return JSON.parse(resp); |         return JSON.parse(resp); | ||||||
|       }).catch(function (e) { |       }).catch(function (e) { | ||||||
|         console.log('dm sub 2e'); |  | ||||||
|         throw e; |         throw e; | ||||||
|       }); |       }); | ||||||
|     }; |     }; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user