JavaScript Hypertext Processor
- JavaScript 100%
| .idea | ||
| src | ||
| .gitignore | ||
| config.example.json | ||
| index.js | ||
| LICENSE | ||
| package.json | ||
| README.md | ||
| yarn.lock | ||
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.