//routes/admin.js
import express from 'express'
const admin = express.Router()

import loginRoute from './admin/login.js'
admin.use('/login', loginRoute) 

import categoryRoute from './admin/category.js'
admin.use('/category', categoryRoute)
 
export default admin

 

//routes/admin/category.js
import express from 'express'
const category = express.Router()
import settings from '../../settings.js'

category.get('/',function(req,res){
    if(req.session.user){
        settings.pageTitle = 'ទំព័រ​ជំពូក'
        settings.route = '/admin/category'
        res.render('base',{data:settings})
    }else{
        res.redirect('/admin/login')
    }
})

export default category

 

<!--views/admin/index.ejs-->
<link href="/styles/admin/index.css" rel="stylesheet">

<section class="Header">
    <div class="wrapper region">
        <div class="logo"><%= data.pageTitle %></div>
        <form method="post" action="/search">
            <select name="type">
                <option>ការផ្សាយ</option>
                <option>ទំព័រស្តាទិក</option>
                <option>អ្នក​ប្រើប្រាស់</option>
            </select>
            <input type="text" name="q" placeholder="Search" required>
            <input type="submit" value="ស្វែង​រក">
        </form>
        <div class="logout">
            <a href="/">ទំព័រ​មុខ</a> | <a href="/admin/logout">ចេញ​ក្រៅ</a>
        </div>
    </div>
</section>

<section class="Body">
    <div class="wrapper region">
        <div class="sidebar">
            <a href='/admin/post'><img src='/images/movie.png' /></a>
            <a href='/admin/post'>ការផ្សាយ</a>
            
            <a href='/admin/category'><img src='/images/category.png' /></a>
            <a href='/admin/category'>ជំពូក</a>
            
            <a href='/admin/book'><img src='/images/books.png' /></a>
            <a href='/admin/book'>សៀវភៅ</a>
            
            <a href='/admin/upload'><img src='/images/upload.png' /></a>
            <a href='/admin/upload'>Upload</a>
            
            <a href='/admin/user'><img src='/images/users.png' /></a>
            <a href='/admin/user'>អ្នក​ប្រើប្រាស់</a>
            
            <a href='/admin/setting'><img src='/images/setting.png' /></a>
            <a href='/admin/setting'>Setting</a>
        </div>
        <div class="Content">
            <% if(data.route.includes('/category')){ %>
                <%- include('category.ejs') %>
            <% } %>
        </div>
    </div>
</section>

 

<!--views/admin/category.ejs-->
<link href="/styles/admin/category.css" rel="stylesheet"></link>

    <div class='content'>
        <form action='/admin/category' method='post' >
            <a>ឈ្មោះជំពូកៈ</a><input type='text' name='label' required />
            <a>រូបសញ្ញាៈ</a><input type='text' name='thumb' required />
            <a>ពេល​បង្កើតៈ</a><input type='datetime-local' value='' name="datetime" required />
            <a></a><input type='submit' value='បញ្ជូនទិន្នន័យ' />
        </form>
    </div>

 

/* public/styles/admin/category.css */
.content form{
    width: 60%;
    display: grid;
    grid-template-columns: 20% 80%;
    grid-gap: 5px;
    align-items: center;
}
 
.content form input{
    padding: 5px 10px;
}
 
.content form input[type=submit]{
    font: var(--body-font);
}
 
.content form a{
    text-align: right;
    color: black;
}

 

GitHub: https://github.com/Sokhavuth/Blog_

Vercel: https://khmerweb-blog.vercel.app/