Skip to content

Commit

Permalink
feat(): Adds a way to display content from GitHub to the website
Browse files Browse the repository at this point in the history
It allows to have some pages that will mirror content stored on openfab's repository
cf openfab-lab#22

(cherry picked from commit 86e903d)
  • Loading branch information
121593 committed Apr 15, 2020
1 parent a8556a2 commit 6744036
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"express": "4.16.2",
"lodash": "4.17.15",
"mailgun-js": "0.21.0",
"md-mirror": "^1.0.0",
"node-sass-middleware": "0.11.0",
"passport": "0.4.0",
"pg": "7.4.1",
Expand Down
1 change: 1 addition & 0 deletions src/authentication/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const publicRoutes = {
'/contact': ['GET', 'POST'],
'/membres': ['GET'],
'/healthcheck': ['GET'],
'/md': ['GET'],
'/inscription': ['GET', 'POST']
};

Expand Down
20 changes: 20 additions & 0 deletions src/controllers/md.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const mdMirror = require('md-mirror')

module.exports = (req, res) => {

const mm = new mdMirror({
baseLocalUrl: '/md',
baseRemoteUrl: 'https://raw.githubusercontent.com/openfab-lab',
viewManager: (content) => {
// While caching is not available set pages to be cached 24h
res.setHeader('Cache-Control', 'public, max-age=' + (60*60*24));
res.render('../src/views/md.ejs', {
content,
user: req.user
})
}
})

return mm.render(req.url)
}

3 changes: 3 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const sassMiddleware = require('node-sass-middleware');
const autoroute = require('./libs/autoroute');
const applyAuthentication = require('./authentication');

const mdDisplay = require('./controllers/md')

const log = require('saga-logger').create({
module: module.id
});
Expand Down Expand Up @@ -63,6 +65,7 @@ module.exports = () => {
applyAuthentication(app);

app.use('/', router);
app.get('/md/*', mdDisplay);

app.all('*', (req, res, next) => {
next(new ManagedError('API_GENERAL', 404));
Expand Down
26 changes: 26 additions & 0 deletions src/views/md.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%- include('./layout/top', {page: 'membre'}); %>
<!-- IFRAME TRICK -->
<!--
<div class="container-fluid">
<div class="row">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" srcdoc="<html>
<head><%= '<link rel="stylesheet" href="https://unpkg.com/sakura.css/css/sakura.css" type="text/css">' %></head>
<body><%= content %></body>
</html>"></iframe>
</div>
</div>
</div>
-->

<div class="container mdcontent mt-5">
<style>.mdcontent img {
max-width: 100%
}</style>
<div class="row">
<div class="col-12">
<%- content %>
</div>
</div>
</div>
<%- include('./layout/bottom'); %>

0 comments on commit 6744036

Please sign in to comment.