yeojz / metalsmith-react-templates

A metalsmith plugin to render files using React / Preact / JSX based templates.
MIT License
92 stars 17 forks source link

How would you go about supporting Helmet server-side? #56

Closed manuhabitela closed 6 years ago

manuhabitela commented 6 years ago

Hi,

Thanks a lot for your plugin :)

I'm using it with a simple default React setup in static mode only, but I'm having trouble making React Helmet work server-side (or I guess we should say "in static mode only" here).

I would like to be able to access helmet instance properties within the html template used as baseFile and maybe have something like this:

<!-- base.html -->
<!DOCTYPE html>
<html {{helmet.htmlAttributes}}>
    <head>
        {{helmet.title}}
        {{helmet.meta}}
        {{helmet.link}}
    </head>
    <body {{helmet.bodyAttributes}}>
        <div id="app">
            {{contents}}
        </div>
    </body>
</html>

My idea was to create a new strategy for jsx-render-engine that would return helmet properties in addition to the react markup. But since this is all tied to the contents property I don't think I can go around it. Here is an example of what I tried to do. I ended up concluding that adding a way to customize how template data was applied in jsx-render-engine would help.

I'm not an expert of metalsmith nor your plugin (I'm actually just getting started using both), so maybe I'm missing something obvious... sorry if that's the case.

Thanks for your help.

yeojz commented 6 years ago

You're right. It doesn't cover 3rd party additions in that flow..

yeojz commented 6 years ago

ref leimi's PR in #57