Site-wide data: Put .yml, .csv, or .sh files in the assets/data/ folder, and the data they contain will be available to all templates at build time.
Page specific data: Put .yml, .csv, or .sh files in the assets/data/my-cool-page/ folder, and the data they contain will be available to the page my-cool-page only at build time.
Details
less code, more config
site data now defined in YAML (assets/data/site.yml)
page/post data defined in YAML in frontmatter (in top of .mdsh files)
better separation of build data and templates
only get site data from assets/data folder (not .site_config)
only get post/page data from yaml frontmatter or assets/data
fewer custom functions used by templates to generate data, more arrays
nicer file structure
fewer files, simpler file naming/layout
changed various scripts into functions
cleaner templates
removed all shell funcs in templates, replaced with:
site/page arrays accessed via the foreach iterator
better partial handling
Other new features
The foreach iterator
adds a foreach iterator to the templating system
Easier data debugging
added a DEBUG_DATA env var, set to true to see site data printed in terminal during build
page_layout variable
Easily render pages with different layouts
Define it in the page front matter, or pass it in via CLI when running create_page.sh (defaults to main if empty, and must be the name of a template file in .app/templates/*/)..
Fixes
added .nojekyll file, used by GitHub to help identify Jekyll sites (or not)
ebc78c3
Added a .yml parser & csv parser func, updated cli-interface to parse data files on each build:
Updates in .app.cli-interface.bash to scan the assets/data dir for files, and parse them into vars and arrays that our build scripts and templates can use...
YAML parsers used:
.app/functions/yay - custom version of yay with added stuff:
fixes and added support for multiple nested levels
fixes for handling simple lists, and other YAML syntaxes
TLDR: better at creating the associative arrays our templates need
.app/functions/ysh - a parser called yaml.sh
used only inside the lookup method
the lookup method only calls ysh if no site data vars/arrays found
else it returns the matching values from the vars/arrays
CSV parser:
shell function called csvToData, in .app/functions/liquid_filters.bash
turns CSV data into bash associative arrays that our templates can use
Much easier to use arrays in templates:
Added a foreach iterator function, to be used in the templates, small fix to mo script to make it work OK.
An example!!
assets/data/products.yml contains:
product1:
name: Foo
price: 10
product2:
name: Bar
price: 20
so you access it in your templates like so:
{{#foreach product in products}}
{{product.name}} costs {{product.price}}
{{/foreach}}
An early attempt at solving https://github.com/sc0ttj/mdsh/issues/65
What's the improvement?
New feature: the
assets/data
folderSite-wide data: Put
.yml
,.csv
, or.sh
files in theassets/data/
folder, and the data they contain will be available to all templates at build time.Page specific data: Put
.yml
,.csv
, or.sh
files in theassets/data/my-cool-page/
folder, and the data they contain will be available to the pagemy-cool-page
only at build time.Details
assets/data/site.yml
).mdsh
files)assets/data
folder (not.site_config
)assets/data
foreach
iteratorOther new features
The
foreach
iteratorforeach
iterator to the templating systemEasier data debugging
DEBUG_DATA
env var, set totrue
to see site data printed in terminal during buildpage_layout
variableEasily render pages with different layouts
Define it in the page front matter, or pass it in via CLI when running
create_page.sh
(defaults tomain
if empty, and must be the name of a template file in.app/templates/*/
)..Fixes
Implementation of data folder
Added example data files:
site.yml
,products.yml
,people.csv
,arrays-example.sh
Pull in data at build time:
Added a .yml parser & csv parser func, updated cli-interface to parse data files on each build:
Updates in
.app.cli-interface.bash
to scan theassets/data
dir for files, and parse them into vars and arrays that our build scripts and templates can use...YAML parsers used:
.app/functions/yay
- custom version ofyay
with added stuff:.app/functions/ysh
- a parser calledyaml.sh
lookup
methodlookup
method only callsysh
if no site data vars/arrays foundCSV parser:
csvToData
, in.app/functions/liquid_filters.bash
Much easier to use arrays in templates:
Added a foreach iterator function, to be used in the templates, small fix to mo script to make it work OK.
An example!!
assets/data/products.yml
contains:TODO:
foreach
iterator with mutiple filters