diff --git a/classes/File.js b/classes/File.js index 117553d07..e34fa6664 100644 --- a/classes/File.js +++ b/classes/File.js @@ -207,4 +207,13 @@ class DataType { } } -module.exports = { File, PageType, CollectionPageType, ResourcePageType, ResourceType, ImageType, DocumentType, DataType } +class HomepageType { + constructor() { + this.folderName = 'index.md' + } + getFolderName() { + return this.folderName + } +} + +module.exports = { File, PageType, CollectionPageType, ResourcePageType, ResourceType, ImageType, DocumentType, DataType, HomepageType } diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css deleted file mode 100644 index 5a9d68689..000000000 --- a/public/stylesheets/style.css +++ /dev/null @@ -1,14 +0,0 @@ -body { - padding: 50px; - font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; -} - -a { - color: #00B7FF; -} - -.edit-box { - margin: 20px 0px; - height: 300px; - border: 1px solid grey; -} \ No newline at end of file diff --git a/routes/homepage.js b/routes/homepage.js new file mode 100644 index 000000000..a611fe14e --- /dev/null +++ b/routes/homepage.js @@ -0,0 +1,56 @@ +const express = require('express'); +const router = express.Router(); +const jwtUtils = require('../utils/jwt-utils') + +// Import classes +const { File, HomepageType } = require('../classes/File.js') + +// Constants +const HOMEPAGE_INDEX_PATH = '' // Empty string + +// Read homepage index file +router.get('/:siteName/homepage', async function(req, res, next) { + try { + const { oauthtoken } = req.cookies + const { access_token } = jwtUtils.verifyToken(oauthtoken) + + const { siteName } = req.params + + const IsomerFile = new File(access_token, siteName) + const homepageType = new HomepageType() + IsomerFile.setFileType(homepageType) + const { sha, content } = await IsomerFile.read(HOMEPAGE_INDEX_PATH) + + // TO-DO: + // Validate content + + res.status(200).json({ content, sha }) + } catch (err) { + console.log(err) + } +}) + +// Update homepage index file +router.post('/:siteName/homepage', async function(req, res, next) { + try { + const { oauthtoken } = req.cookies + const { access_token } = jwtUtils.verifyToken(oauthtoken) + + const { siteName } = req.params + const { content, sha } = req.body + + // TO-DO: + // Validate content + + const IsomerFile = new File(access_token, siteName) + const homepageType = new HomepageType() + IsomerFile.setFileType(homepageType) + const { newSha } = await IsomerFile.update(HOMEPAGE_INDEX_PATH, content, sha) + + res.status(200).json({ content, sha: newSha }) + } catch (err) { + console.log(err) + } +}) + +module.exports = router; \ No newline at end of file diff --git a/server.js b/server.js index 818cc510c..b55ac69a7 100644 --- a/server.js +++ b/server.js @@ -21,6 +21,7 @@ const resourcePagesRouter = require('./routes/resourcePages') const imagesRouter = require('./routes/images') const documentsRouter = require('./routes/documents') const menuRouter = require('./routes/menus') +const homepageRouter = require('./routes/homepage') const app = express(); @@ -48,6 +49,7 @@ app.use('/sites', resourcePagesRouter) app.use('/sites', imagesRouter) app.use('/sites', documentsRouter) app.use('/sites', menuRouter) +app.use('/sites', homepageRouter) // catch 404 and forward to error handler app.use(function(req, res, next) {