diff options
| author | Camil Staps | 2021-06-23 10:28:05 +0200 | 
|---|---|---|
| committer | Camil Staps | 2021-06-23 10:28:36 +0200 | 
| commit | 8e5dc18b9a655200e3355410e812e49db27a4171 (patch) | |
| tree | 21b387fd9ffe89b579fc2c7e6c6b125f3146c393 /resources/pug/include | |
| parent | Setup infrastructure for articles written in markdown (diff) | |
Arrange menu on /articles by year
Diffstat (limited to 'resources/pug/include')
| -rw-r--r-- | resources/pug/include/layout-articles.pug | 4 | ||||
| -rw-r--r-- | resources/pug/include/layout-sidebar.pug | 45 | 
2 files changed, 40 insertions, 9 deletions
| diff --git a/resources/pug/include/layout-articles.pug b/resources/pug/include/layout-articles.pug index 88b1aea..26fa69f 100644 --- a/resources/pug/include/layout-articles.pug +++ b/resources/pug/include/layout-articles.pug @@ -4,5 +4,7 @@ block append menu  	- var base_url = '/articles/'  	+menu(  		{name: 'Home', link: ''}, -		{name: 'Clean Sandbox', year: 2021, month: 6, day: 22}, +		{name: 2021, menu: [ +			{name: 'Clean Sandbox', year: 2021, month: 6, day: 22}, +		]},  	) diff --git a/resources/pug/include/layout-sidebar.pug b/resources/pug/include/layout-sidebar.pug index 8cf7d5a..265564d 100644 --- a/resources/pug/include/layout-sidebar.pug +++ b/resources/pug/include/layout-sidebar.pug @@ -1,22 +1,51 @@  extends layout.pug +block prepend js +	script(src='/assets/js/jquery.slim.min.js') +	script(src='/assets/js/transition.min.js') +	script(src='/assets/js/collapse.min.js') +  block content  	div.row  		div.col-lg-3.col-md-4  			ul.nav.nav-pills.nav-stacked  				block menu  					mixin menu(...items) -						- const pad_zero = n => n < 10 ? '0' + n : n; +						- +							function pad_zero (n) { +								return n < 10 ? '0' + n : n; +							} -						each item in items -							if typeof item.link == 'undefined' -								- item.link = item.name.toLowerCase().replace(/\W/g, '-') +							function item_link (item) { +								if (!('link' in item)) { +									item.link = new String(item.name).toLowerCase().replace(/\W/g, '-'); + +									if ('year' in item && 'month' in item && 'day' in item) +										item.link = item.year + '-' + pad_zero(item.month) + '-' + pad_zero(item.day) + '-' + item.link; +								} -							unless typeof item.year == 'undefined' || typeof item.month == 'undefined' || typeof item.day == 'undefined' -								- item.link = item.year + '-' + pad_zero(item.month) + '-' + pad_zero(item.day) + '-' + item.link +								return item.link; +							} + +							function item_is_active (item) { +								return item_link(item) == page; +							} + +						each item in items +							if 'menu' in item +								- const active = item.menu.some(item_is_active) +								li(role='presentation') +									- const id = 'menu-' + item_link(item); +									a(href='#' + id, data-toggle='collapse', role='button', aria-expanded=active.toString(), aria-controls=id)= item.name +									div.collapse(id=id, class=active ? 'in' : '') +											ul.nav.nav-pills.nav-stacked.col-xs-12.col-md-10.pull-right +												+menu(...item.menu) +											br(style='clear:both;') -							li(role='presentation', class=(page == item.link) ? 'active' : '') -								a(href=base_url + (item.link == '' ? '' : item.link + '.html'))= item.name +							else +								- var link = item_link(item) +								li(role='presentation', class=item_is_active(item) ? 'active' : '') +									a(href=base_url + (link == '' ? '' : link + '.html'))= item.name  		div.col-lg-7.col-md-6  			h3 | 
