1

I've set up Harp, and it is running and serving content, but any values stored in _data.json seem to have no effect.

Directory structure:

/
|-- _harp.json
|-- _data.json
|-- _layout.ejs
|-- index.md
|-- getting-started.md

The file _harp.json contains:

{
        "globals": {
                "title": "Home"
        }
}

_data.json contains:

{
        "getting-started": {
                "title": "Getting Started"
        }
}

And _layout.ejs contains:

<!DOCTYPE html>
<html>
        <head>
                <title><%= title %> &mdash; My Website</title>
        </head>
        <body>
               <%- yield %>
        </body>
</html>

The layout, and page contents, load correctly, and <%= title %> is replaced with the value given in _harp.json. However, when an entry exists within _data.json, no replacement is made and it continues to be replaced with the value in _harp.json.

Have I missed the obvious with this? Thank you in advance.

LMS
  • 4,117
  • 5
  • 27
  • 37

2 Answers2

1

It appears that Harp required a restart, although this wasn't mentioned in Harp's documentation. It also appears to require a restart each time _data.json is modified.

LMS
  • 4,117
  • 5
  • 27
  • 37
0

The solution

I've run into the same problem, and just found the solution.

It appears in my case, the harp server was launched with NODE_ENV=production which has exactly this side effect (see https://harpjs.com/docs/environment/server in the end of the page). Explicitly set NODE_ENV=development solved the problem.

More informations on environment

https://harpjs.com/docs/development/environment

Note

NODE_ENV=development is the default, you need to explicitly set NODE_ENV=production for production purpose.

In my case, I use an already built docker container ( dockerimages/harp ) which default is to use NODE_ENV=production which is why I didn't realize it was set for production as default.

To use that image for development you must put:

$ docker [...] --env NODE_ENV=development [...] dockerimages/harp

gissehel
  • 181
  • 7