Add readme accessible from web app

This commit is contained in:
Christian Bundy 2019-09-24 14:22:31 -07:00
parent d9623fbe04
commit 5140301cd7
No known key found for this signature in database
GPG Key ID: EB541AAEF4366237
5 changed files with 34 additions and 3 deletions

View File

@ -3,6 +3,8 @@
'use strict'
const yargs = require('yargs')
const fs = require('fs').promises
const path = require('path')
const config = yargs
.env('OASIS')
@ -39,6 +41,12 @@ process.argv = []
if (config.debug) {
process.env.DEBUG = '*'
}
const app = require('./src/app')
app(config)
const start = async () => {
config.readme = await fs.readFile(path.join(__dirname, 'README.md'), 'utf8')
app(config)
}
start()

View File

@ -26,6 +26,7 @@ const image = require('./pages/image')
const blob = require('./pages/blob')
const compose = require('./pages/compose')
const publish = require('./pages/publish')
const markdown = require('./pages/markdown')
module.exports = (config) => {
const assets = new Koa()
@ -97,6 +98,9 @@ module.exports = (config) => {
.get('/status/', async (ctx) => {
ctx.body = await status()
})
.get('/readme/', async (ctx) => {
ctx.body = await markdown(config.readme)
})
.get('/mentions/', async (ctx) => {
ctx.body = await mentions()
})

7
src/pages/markdown.js Normal file
View File

@ -0,0 +1,7 @@
'use strict'
const markdownView = require('./views/markdown')
module.exports = async function statusPage (text) {
return markdownView({ text })
}

View File

@ -36,8 +36,7 @@ module.exports = (...elements) => {
li(a({ href: '/compose' }, 'compose')),
li(a({ href: '/profile' }, 'profile')),
li(a({ href: '/status' }, 'status')),
li(a({ href: 'https://github.com/fraction/oasis' }, 'source')),
li(a({ href: 'https://github.com/fraction/oasis/issues/new/choose' }, 'help'))
li(a({ href: '/readme' }, 'readme'))
)
),
main({ id: 'content' }, ...elements)

View File

@ -0,0 +1,13 @@
'use strict'
const { section } = require('hyperaxe')
const ssbMarkdown = require('ssb-markdown')
const template = require('./components/template')
module.exports = ({ text }) => {
const rawHtml = ssbMarkdown.block(text)
return template(
section({ class: 'message' }, { innerHTML: rawHtml })
)
}