Skip to content
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

Add support for multiple template engines #44

Open
ThaNarie opened this issue Mar 9, 2022 · 2 comments
Open

Add support for multiple template engines #44

ThaNarie opened this issue Mar 9, 2022 · 2 comments

Comments

@ThaNarie
Copy link
Contributor

ThaNarie commented Mar 9, 2022

Currently, the skeleton can only render TS templates – which will stay the preferred way of working.

However, certain projects might benefit from other template languages – like Twig or Handlebars – that better connect with the CMS used in a project.

Since we're using express already to render templates "on the server", and @muban/storybook does support server-side template rendering, we could leverage that to basically support any template engine that express supports – and potentially more.

Goals

  • Be able to render a page, using multiple nested templates
  • Still allow our current "data" setup for pages, but those are passed to templates
  • Still allow defining types for the nested template structure, even though it's not used in the TS templates anymore
  • Add an endpoint to render individual templates "on the server", and configure storybook to load those (instead of the TS templates currently defined in the stories)
@ThaNarie
Copy link
Contributor Author

Approach (WIP)

In the MubanWebpackConfig > finalDevServer, make the setupMiddlewares allow for different types of template engines (or abstract it away as "plugins").

Example for handlebars:

devServer.app.engine('.hbs', engine({ extname: '.hbs'}));
devServer.app.set('view engine', '.hbs');
devServer.app.set('views', './views');

middlewares.unshift({
  name: 'pages',
  path: '/',
  middleware: ((req, res, next) => {
    res.render('home');
  }),
});

Update the MubanPagePlugin > generatePageAssets to (also) output the raw "page data" instead of (only) the rendered HTML, so the middleware above can make use of this data to render the page based on chosen template engine.

Currently running into issues also setting this in compilation.hooks.processAssets.tapPromise

assets[page.replace('.html', '.json')] = JSON.stringify(pageData);

TypeError: Invalid value used as weak map key

@psimk
Copy link

psimk commented Mar 14, 2022

"transfered" to mediamonks/pota#30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants