Commit abf8becd authored by Aral Balkan's avatar Aral Balkan
Browse files

Refactored the template rendering to remove redundancy. Closes #66.

parent 5bedbe99
Pipeline #51 skipped
......@@ -196,9 +196,9 @@ class App
header: fs.readFileSync (path.join dataTemplatesDirectory, 'header.html'), 'utf-8'
footer: fs.readFileSync (path.join dataTemplatesDirectory, 'footer.html'), 'utf-8'
home: fs.readFileSync (path.join dataTemplatesDirectory, 'home.html'), 'utf-8'
sitesIndex: fs.readFileSync (path.join dataTemplatesDirectory, 'sites/index.html'), 'utf-8'
trackersIndex: fs.readFileSync (path.join dataTemplatesDirectory, 'trackers/index.html'), 'utf-8'
companiesIndex: fs.readFileSync (path.join dataTemplatesDirectory, 'companies/index.html'), 'utf-8'
sites: fs.readFileSync (path.join dataTemplatesDirectory, 'sites/index.html'), 'utf-8'
trackers: fs.readFileSync (path.join dataTemplatesDirectory, 'trackers/index.html'), 'utf-8'
companies: fs.readFileSync (path.join dataTemplatesDirectory, 'companies/index.html'), 'utf-8'
graph: fs.readFileSync (path.join dataTemplatesDirectory, 'sites/graph.html'), 'utf-8'
table: fs.readFileSync (path.join dataTemplatesDirectory, 'sites/table.html'), 'utf-8'
......@@ -207,9 +207,9 @@ class App
# footer: fs.readFileSync (path.join siteTemplatesDirectory, 'footer.html'), 'utf-8'
page: fs.readFileSync (path.join siteTemplatesDirectory, 'page.html'), 'utf-8'
home: fs.readFileSync (path.join siteTemplatesDirectory, 'home.html'), 'utf-8'
sitesIndex: fs.readFileSync (path.join siteTemplatesDirectory, 'sites/index.html'), 'utf-8'
trackersIndex: fs.readFileSync (path.join siteTemplatesDirectory, 'trackers/index.html'), 'utf-8'
companiesIndex: fs.readFileSync (path.join dataTemplatesDirectory, 'companies/index.html'), 'utf-8'
sites: fs.readFileSync (path.join siteTemplatesDirectory, 'sites/index.html'), 'utf-8'
trackers: fs.readFileSync (path.join siteTemplatesDirectory, 'trackers/index.html'), 'utf-8'
companies: fs.readFileSync (path.join dataTemplatesDirectory, 'companies/index.html'), 'utf-8'
graph: fs.readFileSync (path.join siteTemplatesDirectory, 'sites/graph.html'), 'utf-8'
table: fs.readFileSync (path.join siteTemplatesDirectory, 'sites/table.html'), 'utf-8'
......
......@@ -295,62 +295,49 @@ class Blockdown
htmlFileName = "#{pathObject.name}.html"
indices[relativeFolder].push htmlFileName
# console.log themeHeaderAfterTemplateSubstitutions
# Generate the navigation list for local links
navigationList = []
# Selected item
selectedItem = ''
currentDirectory = pathObject.dir
parts = currentDirectory.split('/content/')
if parts.length >= 2
navigationList = @navigationList(parts[1])
themeHeaderPartialHTML = @partial(set.render(theme.header, {navigationList: navigationList}))
content = set.render(theme.page, {title: titleOfPage, header: themeHeaderPartialHTML, content: content})
selectedItem = parts[1]
# Write out the HTML.
filePath = file.replace contentPath, dataPath
filePath = filePath.replace '.md', '.html'
# Path for page.
pagePath = file.replace contentPath, dataPath
pagePath = pagePath.replace '.md', '.html'
fs.outputFileAsync filePath, content
# Render the page.
headerPartialHTML = @partial(set.render(@theme.header, {navigationList: @navigationList selectedItem}))
pageHTML = set.render(@theme.page, {title: titleOfPage, header: headerPartialHTML, content: content})
fs.outputFileAsync pagePath, pageHTML
.then =>
# Generate and save the /sites index
sitesIndexMainSectionPartialHTML = @partial(set.render(@theme.sitesIndex, {list: indexContent.sites}))
navigationList = @navigationList 'sites'
sitesIndexHeaderPartialHTML = @partial(set.render(@theme.header, {navigationList: navigationList}))
sitesIndexHTML = set.render(@theme.page, {title: 'Sites', header: sitesIndexHeaderPartialHTML, content: sitesIndexMainSectionPartialHTML})
sitesIndexPath = path.join dataPath, '/sites/index.html'
fs.outputFileAsync sitesIndexPath, sitesIndexHTML
@info 'Generated and wrote the sites index.'
@renderPage 'sites', dataPath, '/sites/index.html', {list: indexContent.sites}
.then =>
# Generate and save the /trackers index
trackersIndexMainSectionPartialHTML = @partial(set.render(@theme.trackersIndex, {list: indexContent.trackers}))
navigationList = @navigationList 'trackers'
trackersIndexHeaderPartialHTML = @partial(set.render(@theme.header, {navigationList: navigationList}))
trackersIndexHTML = set.render(@theme.page, {title: 'Trackers', header: trackersIndexHeaderPartialHTML, content: trackersIndexMainSectionPartialHTML})
trackersIndexPath = path.join dataPath, '/trackers/index.html'
fs.outputFileAsync trackersIndexPath, trackersIndexHTML
@info 'Generated and wrote the trackers index.'
# Render /trackers index.
@renderPage 'trackers', dataPath, '/trackers/index.html', {list: indexContent.trackers}
.then =>
# Generate and save the /companies index
companiesIndexMainSectionPartialHTML = @partial(set.render(@theme.companiesIndex, {list: indexContent.companies}))
navigationList = @navigationList 'companies'
companiesIndexHeaderPartialHTML = @partial(set.render(@theme.header, {navigationList: navigationList}))
companiesIndexHTML = set.render(@theme.page, {title: 'Companies', header: companiesIndexHeaderPartialHTML, content:companiesIndexMainSectionPartialHTML})
companiesIndexPath = path.join dataPath, '/companies/index.html'
fs.outputFileAsync companiesIndexPath, companiesIndexHTML
@info 'Generated and wrote the companies index.'
# Render /companies index.
@renderPage 'companies', dataPath, '/companies/index.html', {list: indexContent.companies}
.then =>
# Generate and save the home page
homePageMainSectionPartialHTML = @partial(set.render(@theme.home, {}))
navigationList = @navigationList 'home'
homePageHeaderPartialHTML = @partial(set.render(@theme.header, {navigationList: navigationList}))
homePageHTML = set.render(@theme.page, header: homePageHeaderPartialHTML, content: homePageMainSectionPartialHTML)
homePagePath = path.join dataPath, '/index.html'
fs.outputFileAsync homePagePath, homePageHTML
@info 'Generated and wrote the home page.'
# Render home page.
@renderPage 'home', dataPath, '/index.html', {}
.then =>
return indices
#
# Renders a page on the site.
#
renderPage: (name, dataPath, pathFragment, data={}) =>
theme = @theme[name]
contentPartialHTML = @partial(set.render(theme, data))
navigationList = @navigationList name
headerPartialHTML = @partial(set.render(@theme.header, {navigationList: navigationList}))
title = name[0].toUpperCase() + name.slice(1) # title is the name with the first letter capitalised.
pageHTML = set.render(@theme.page, {title: title, header: headerPartialHTML, content: contentPartialHTML})
pagePath = path.join dataPath, pathFragment
fs.outputFileAsync pagePath, pageHTML
#
# Returns configured navigation list data structure with the
# passed navigation element marked as selected.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment