diff --git a/backend/core/core.js b/backend/core/core.js index 459272e..501d116 100644 --- a/backend/core/core.js +++ b/backend/core/core.js @@ -21,23 +21,19 @@ let settings = { HIDE_LOGIN: false, BLOG_UPLOADING: false, - CD_RSS: false, - CD_AP: false, + CD_RSS: true, + CD_JSON: true, WEBSITE_NAME: "", PLAUSIBLE_URL: "", USER_MINIMUM_PASSWORD_LENGTH: 7, - BLOG_MINIMUM_TITLE_LENGTH: 7, - BLOG_MINIMUM_DESCRIPTION_LENGTH: 7, - BLOG_MINIMUM_CONTENT_LENGTH: 7, + theme: "default", }; let use_s3_storage = false; -let groups = []; _initS3Storage(); _getSettings(); -_getGroups(); // Checks to see if S3 storage is set function _initS3Storage() { @@ -505,14 +501,16 @@ async function postSetting(key, value) { if (!Object.keys(settings).includes(key)) return { success: false, message: "Setting not valid" }; await prisma.setting.upsert({ where: { id: key }, update: { value: value }, create: { id: key, value: value } }); - settings[key] = JSON.parse(value); + try { + settings[key] = JSON.parse(value); + } catch { + settings[key] = value; + } return { success: true }; } catch (e) { return { success: false, message: e.message }; } } -async function _getGroups() { - const group_list = await prisma.group.findMany(); -} + module.exports = { settings, registerUser, getUser, getAuthorPage, postBlog, updateBlog, getBlog, deleteBlog, deleteImage, postSetting, getSetting }; diff --git a/backend/page_scripts.js b/backend/page_scripts.js index ecd7216..ae075e0 100644 --- a/backend/page_scripts.js +++ b/backend/page_scripts.js @@ -1,6 +1,10 @@ const external = require("./core/external_api"); const core = require("./core/core"); +function getThemePage(page_name) { + return `themes/${core.settings.theme}/ejs/${page_name}.ejs`; +} + function getDefaults(req) { // TODO: Fix reference to website_name return { logged_in_user: req.session.user, website_name: core.settings.WEBSITE_NAME || "Yet-Another-Blog", settings: core.settings }; @@ -8,27 +12,35 @@ function getDefaults(req) { async function index(request, response) { // Check if the master admin has been created - const is_setup_complete = core.settings["SETUP_COMPLETE"]; - if (!is_setup_complete) return response.redirect("/register"); + // const is_setup_complete = core.settings["SETUP_COMPLETE"]; + // if (!is_setup_complete) return response.redirect("/register"); - response.redirect("/blog"); + const blog_list = await core.getBlog({ owner_id: request.session.user?.id, page: request.query.page || 0 }); + response.render(getThemePage("index"), { + ...getDefaults(request), + blog_list: blog_list.data, + pagination: blog_list.pagination, + current_page: request.query.page || 0, + loaded_page: request.path, + }); } function register(request, response) { response.render("register.ejs", getDefaults(request)); } function login(request, response) { - response.render("login.ejs", getDefaults(request)); + response.render(getThemePage("login"), getDefaults(request)); } async function author(req, res) { const user = await core.getUser({ id: req.params.author_id }); // FIXME: Bandage fix for author get error if (!user.success) return res.redirect("/"); const profile = await core.getAuthorPage({ author_id: user.data.id }); - res.render("author.ejs", { ...getDefaults(req), blog_post: profile.data }); + console.log(profile.data); + res.render(getThemePage("author"), { ...getDefaults(req), post: profile.data }); } async function blogList(req, res) { const blog_list = await core.getBlog({ owner_id: req.session.user?.id, page: req.query.page || 0, search: req.query.search, search_tags: true, search_title: true }); - res.render("blogList.ejs", { + res.render(getThemePage("postSearch"), { ...getDefaults(req), blog_list: blog_list.data, pagination: blog_list.pagination, @@ -38,8 +50,8 @@ async function blogList(req, res) { } async function blogSingle(req, res) { const blog = await core.getBlog({ id: req.params.blog_id }); - if (blog.success === false) return res.redirect("/blog"); - res.render("blogSingle.ejs", { ...getDefaults(req), blog_post: blog.data }); + if (blog.success === false) return res.redirect("/"); + res.render(getThemePage("post"), { ...getDefaults(req), blog_post: blog.data }); } function blogNew(request, response) { // TODO: Turn date formatting into function @@ -69,7 +81,7 @@ async function blogEdit(req, res) { res.render("blogNew.ejs", { ...getDefaults(req), existing_blog: existing_blog }); } async function admin(request, response) { - response.render("admin.ejs", { ...getDefaults(request) }); + response.render(getThemePage("admin-settings"), { ...getDefaults(request) }); } async function atom(req, res) { res.type("application/xml"); diff --git a/frontend/public/css/login.css b/frontend/public/css/login.css new file mode 100644 index 0000000..9dcc99d --- /dev/null +++ b/frontend/public/css/login.css @@ -0,0 +1,38 @@ +.page .page-center { + margin-top: 2rem; +} +.page .page-center .page-modal { + width: 400px; + height: 200px; + background-color: white; + margin: auto; + padding: 1rem; + box-sizing: border-box; +} +.page .page-center .page-modal .title { + font-size: 1.4rem; + text-align: center; +} +.page .page-center .page-modal .login-part { + width: 100%; + margin-bottom: 1rem; +} +.page .page-center .page-modal .login-part input { + width: 100%; + padding: 0.25rem; + box-sizing: border-box; +} +.page .page-center .page-modal .action-container { + display: flex; + flex-direction: row-reverse; +} +.page .page-center .page-modal .action-container button { + width: 100px; + padding: 0.25rem; + box-sizing: border-box; + margin-left: auto; + height: 30px; +} +.page .page-center .page-modal .action-container a { + margin: auto auto auto 0; +} \ No newline at end of file diff --git a/frontend/views/admin.ejs b/frontend/views/admin.ejs deleted file mode 100644 index ff02d16..0000000 --- a/frontend/views/admin.ejs +++ /dev/null @@ -1,56 +0,0 @@ - - -
- - - - - -