Add olegdb-cached readme parser
Will take any of my projects and render a README.md
This commit is contained in:
parent
8e47e4e7c8
commit
1f94bb0246
|
@ -1,5 +1,38 @@
|
|||
config = require("lapis.config").get!
|
||||
discount = require "discount"
|
||||
lapis = require "lapis"
|
||||
http = require "lapis.nginx.http"
|
||||
oleg = require "lib/oleg"
|
||||
|
||||
require "base64"
|
||||
|
||||
gh = require('github').new({access_token: os.getenv "GITHUB_TOKEN", httpclient_driver: 'httpclient.ngx_driver'})
|
||||
|
||||
class Projects extends lapis.Application
|
||||
[projects: "/projects"]: =>
|
||||
render: true
|
||||
|
||||
[readme: "/projects/:name"]: =>
|
||||
@ret, @err = oleg.get "readmes", @params.name
|
||||
|
||||
ngx.log ngx.NOTICE, "Got content from oleg, code #{@err}"
|
||||
|
||||
if @err
|
||||
ngx.log ngx.NOTICE, "Need to download readme for #{@params.name}"
|
||||
|
||||
reply, err = gh\authed_request "/repos/Xe/#{@params.name}/contents/README.md"
|
||||
readme = base64.decode reply.content
|
||||
|
||||
if code == 404
|
||||
return render: "notfound", status_code: 404
|
||||
|
||||
oleg.set "readmes", @params.name, readme
|
||||
@ret = readme
|
||||
|
||||
elseif @err
|
||||
@err = "OlegDB returned code #{@err}."
|
||||
return render: "error", status_code: 500
|
||||
|
||||
@doc = discount @ret, "toc", "nopants", "autolink"
|
||||
|
||||
render: true
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
import Widget from require "lapis.html"
|
||||
|
||||
class Readme extends Widget
|
||||
content: =>
|
||||
raw @doc
|
||||
|
Loading…
Reference in New Issue