-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Site to generate default.md based on template #2308
Conversation
siteConvertLayout is not able to directly replicate default.md. This results in changes in default.md not being reflected in siteConvertLayout and vice versa. Furthermore, this makes `markdown init -c` on an empty folder unable to be the exact same as `markdown init`. Let's make siteConvertLayout able to clone default.md For siteConvertLayout to clone default.md while still having the customizability of being a default.md file, siteConvertLayout must have default values embedded. Hence, defaultSiteNav is added as defaultFooter already exists. For Site to generate default.md using siteConvertLayout and its existing functions, Site must know what the template requires. Hence, we need to have a TemplateConfig that Site can use to generate the layout or any possible template layouts. Rather than having Template be referenced in Site or vice versa, we will have the command init.js transfer the TemplateConfig from the promise of template.init() to Site.convert or Site.generateDefaultLayout
Some renaming of variables also occured
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work and thanks for the PR @WillCWX! The changes look quite promising.
Some preliminary overall comments:
- As you mentioned,
TemplateConfig.ts
might not be necessary. However, it still adds a nice avenue for us to easily keep track of new templates if we end up needing more than justdefault
andminimal
. - As mentioned in this comment in Markbind init --convert improvements #1866, we may want to remove default file generation for conversion - for that, we'll want to replace instead of adding to
siteNav
andfooter
. But for now, adding instead of replacing should be fine to work with the default files being generated.
Also, your addition of in-line documentations have been noted & are appreciated 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nit on naming:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - Thanks for the PR @WillCWX!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @WillCWX thanks so much for the work! Sorry for the late review as well.
Some comments regarding the fileSubstitutions :)
|
||
type NjkVars = { | ||
variableName: string, | ||
fileSubstitutes: string[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is an array used here? There should only be one file for each substitution
Changes below shows that the last file will be used anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used an array so that possible variations of file names that could be used as substitutes.
Kind of like how ['README.md', 'Home.md']
is used in addIndexPage()
(link)
Though the current nunjucks variables only have one file name as a substitute, I thought that using an array may allow a greater range of possible file names. (at the cost of some complexity and readability)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see where you are coming from. That;s ok then :)
Also could you change the variable name to something more obvious that its just for files? Eg. NjkFileVars
Also, very minor comment: do make sure to follow the PR template (e.g. the checklist at the beginning for the purpose of PR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the work @WillCWX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea whether this was worth it.
The scope of markbind init --convert is broad and its functions could potentially be used for easy migrations / upgrades.
However, this increase in scope may also unduly burden the Site class as it is the only class currently able to inherently do everything needed to convert. Also Site/index.ts got even longer...
I think this is still worth it alone for eliminating siteConvertLayout.njk
.
I like the idea of TemplateConfig.ts
as well, it sets the ground for adding future templates easily.
this increase in scope may also unduly burden the Site class
As a next step (if you are interested), would it be possible to extract all site initialisation and conversion functionality out of Site
?
I can't imagine initialisation needs much stateful logic (to be contained within a Site
), I see a few references but don't think they should be un-workable around.
It should help out with #1756 greatly
Just a few nits on the PR itself:
packages/core/src/Site/index.ts
Outdated
config.pages.push(layoutObj); | ||
await fs.outputJson(configPath, config); | ||
static async writeToSiteConfig(config: SiteConfig, configPath: string, layoutObjs: SiteConfigPage[]) { | ||
layoutObjs.forEach(layoutObj => config.pages.push(layoutObj)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
layoutObjs.forEach(layoutObj => config.pages.push(layoutObj)); | |
siteConfigPages/pageConfigs.forEach(layoutObj => config.pages.push(layoutObj)); |
I realise this is the old variable name but I don't think its immediately clear (all the way down from TemplateConfig.ts
) where it ends up, would this be more straightforward?
packages/core/src/Site/index.ts
Outdated
const configPath = path.join(this.rootPath, SITE_CONFIG_NAME); | ||
const config = await fs.readJson(configPath); | ||
await Site.writeToSiteConfig(config, configPath); | ||
await Site.writeToSiteConfig(config, configPath, layoutObjs); | ||
} | ||
|
||
/** | ||
* Helper function for addDefaultLayoutToSiteConfig(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Helper function for addDefaultLayoutToSiteConfig(). | |
* Helper function for addTemplateLayoutSettingsToSiteConfig(). |
packages/core/src/Site/index.ts
Outdated
@@ -164,6 +158,10 @@ type DeployOptions = { | |||
user?: { name: string; email: string; }, | |||
}; | |||
|
|||
type NunjuckObj = { | |||
[key: string]: string | undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Standardisation nit: How about Record<string, any>
? We are using that elsewhere for nunjucks variables.
@@ -0,0 +1,14 @@ | |||
<header> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need packages\core\template\minimal\_markbind\layouts\default.md
? (and the default one)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No we don't need it anymore, I'll delete it now that we are okay with how each template .njk
looks in comparison
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I need to keep packages\core\template\minimal\_markbind\layouts\default.md
to make sure git
tracks the empty layouts
folder. I couldn't get git to track the empty folder otherwise.
I made default.md
empty with a message to edit the .njk
file instead.
hasAutoSiteNav: true, | ||
siteNavIgnore: [ | ||
'index.md', '404.md', | ||
'contents/topic1.md', 'contents/topic2.md', 'contents/topic3a.md', 'contents/topic3b.md', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not your pr but possible future work)
For a conversion feature, what do you think of including 'contents/topic1.md', 'contents/topic2.md', 'contents/topic3a.md', 'contents/topic3b.md'
? (personally only just realised its a little odd we are adding pages when doing conversion)
index.md
and 404.md
makes some sense but I don't think we have file.exists
checks or fallback plans if the site already has these files too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a conversion feature, what do you think of including 'contents/topic1.md', 'contents/topic2.md', 'contents/topic3a.md', 'contents/topic3b.md'? (personally only just realised its a little odd we are adding pages when doing conversion)
I think it make sense if we think in terms of
- converting markdown documents into a
default
/minimal
/template
markbind
site
Otherwise the navbar
will have broken links to contents/topic1.md
etc.
Unless we decide to generate the navbar
like how we generate the siteNav
which is also a viable option
index.md and 404.md makes some sense but I don't think we have file.exists checks or fallback plans if the site already has these files too.
The files are copied over using the util function copySyncWithOptions
in Template.init
that allows us to ensure that no file override exists. So the plan is to simply use their index.md
etc. files as they are if they exist.
Some thing went wrong in the previous merge...
@WillCWX (cc @damithc) for any purposes I think we can consider this PR "merged". As site/index.ts was recently reverted #2333 to a |
Sorry as I do not have time currently to rereview this PR due to the large diffs from the merge commit including the revert. But if anyone else can pick things up here please feel free. 🙇 |
@ang-zeyu , thanks for the heads up and for the review previously
Would it be better if I extract all Site initialisation and conversion functionality out of Site first (in a different pull request) before coming back here? This would ensure that
|
Hi @WillCWX are you keen to continue working on this? If we can fix the conflicts and also outline the remaining points for discussion, I'm happy to support reviewing this PR and get a closure on this. |
Apologies for the late reply, I would still like to work on this issue but I think the conflicts found in this pull request (and on my branch) are a bit too much. So I would like to close this pull request as it is. I thinking starting fresh on a new branch/pull request will be easier for me to write new tests for the proposed modified Once again, apologies for the late reply and thanks to everyone for reviewing and helping with this pull request. |
Sure, please aim to make incremental changes (perhaps across multiple PRs) if possible. |
What is the purpose of this pull request?
Attempts to:
Resolve #2293
Overview of changes:
Feature / Behaviour Changes:
markbind init --convert
markbind init
about.md
as it does not appear intemplate/default
Your Logo
as it is indefault.md
404
as a navigation link,404.html
is also now displayed exactly the same as inmarkbind init
-t minimal
and hasdefault.md
be exactly the same as a minimal templatesite.json
is now more readable with indentationsfooter
andsiteNav
nunjucks variables no longer replace their defaults and instead adds to their defaults.markbind init
default.md
is now generated bySite.generateDefaultLayout
rather than copied overCode Maintenance Changes:
default.md
layout:default.md
should no longer exist, update the respective template.njk
nunjucks files instead.TemplateConfig.ts
contains template configurations for both default and minimal.njkFile: string
dictates which nunjucks file to use.njkSubs: NjkVars[]
allows for using nunjucks to copy existing files to incorporate into the layoutdefault.md
layoutObjs: SiteConfigPage[]
allows for edits toconfig
hasAutoSiteNav: boolean
toggles whetherSite.buildSiteNav
is called during a conversionsiteNavIgnore: string[]
contains files thatSite.buildSiteNav
will ignore when making linksAnything you'd like to highlight/discuss:
I have no idea whether this was worth it.
The scope of
markbind init --convert
is broad and its functions could potentially be used for easy migrations / upgrades.However, this increase in scope may also unduly burden the
Site
class as it is the only class currently able to inherently do everything needed to convert. AlsoSite/index.ts
got even longer...TemplateConfig.ts
may not be needed if we decide that templates should be left with justdefault
andminimal
as it is.Testing instructions:
npm run test
passes. The functional tests fortest_site_templates
have not changed but should still pass because the generated default.md for both minimal and default is exactly the same.Fast-ish Manual Tests:
non-markbind-site
from the conversion testsnpm link
with this branchmarkbind init --convert
the copiednon-markbind-site
foldersmarkbind serve
to see that they lookmarkbind init
but with texts different in the front page and additional / inherited links at the side. Additional texts to footer should exist if_Footer.md
is present.Proposed commit message: (wrap lines at 72 characters)
Update Site to generate default layouts
Checklist: ☑️