JavaScript Hypertext Processor
  • JavaScript 100%
Find a file
2022-08-02 23:00:31 -04:00
.idea initial commit 2022-08-02 22:58:15 -04:00
src initial commit 2022-08-02 22:58:15 -04:00
.gitignore initial commit 2022-08-02 22:58:15 -04:00
config.example.json initial commit 2022-08-02 22:58:15 -04:00
index.js initial commit 2022-08-02 22:58:15 -04:00
LICENSE Initial commit 2022-08-02 02:17:16 +00:00
package.json remove unnecessary dependency 2022-08-02 23:00:31 -04:00
README.md initial commit 2022-08-02 22:58:15 -04:00
yarn.lock remove unnecessary dependency 2022-08-02 23:00:31 -04:00

JSHP

JavaScript Hypertext Processor

It's like PHP but JS!

Setup

Do yarn install or npm install to install dependencies.

Copy config.example.json to config.json and configure it the way you like.

JSHP File Syntax

JSHP uses Eta.js for template files. Eta syntax is very similar to EJS, but with some small changes.

Global variables are exposed as a variable called global. It includes the following properties by default:

  • ctx (Koa.js Context object)
  • site (the site's config entry)
  • siteRoot (the absolute path of the site root)
  • config (the application config)
  • getSiteByName (function to return a site by name)
  • getSiteByHostname (function to return a site by hostname)
  • sendFile (async function to send a file)
  • serveFile (async function to serve a file, either a JSHP file or a normal file)
  • next (not available on not found document) (async function to pass to the next handler, usually not found handler)
  • filePath (the path of the current file)
  • fileDir (the containing directory of the current file)
  • fileRelativePath (the relative path of the current file to the site root)
  • require (reference to Node.js require)

Use the includeFile function to include other files like so:

<%~ await includeFile('./stuff.jshp') %>

If you set the body property of global.ctx then the template output will be ignored and the assignment will be used as the body.

That's about it.