setup mongodb
This commit is contained in:
parent
519246973c
commit
9d1a95aa0a
@ -9,17 +9,26 @@ const ArticleSchema = new Schema({
|
||||
},
|
||||
slug: { type: String, required: true, index: { unique: true } },
|
||||
created_at: { type: Date, default: Date.now },
|
||||
html: { type: Blob, required: true },
|
||||
html: { type: String, required: true },
|
||||
comments: [{
|
||||
content: { type: String, required: true },
|
||||
author: { type: String, required: true },
|
||||
created_at: { type: Date, default: Date.now },
|
||||
votes: { type: Number, default: 0 }
|
||||
}],
|
||||
views: { type: Number, default: 0 },
|
||||
votes: { type: Number, default: 0 }
|
||||
});
|
||||
|
||||
|
||||
ArticleSchema.methods.genSlug = () => this.title.toLowerCase().replace(/\W+/g, '-');
|
||||
|
||||
ArticleSchema.pre('findOne', next => {
|
||||
var article = this;
|
||||
article.views++;
|
||||
next();
|
||||
});
|
||||
|
||||
ArticleSchema.pre('save', next => {
|
||||
var article = this;
|
||||
// only gen the slug if title has been modified (or is new)
|
||||
@ -29,6 +38,4 @@ ArticleSchema.pre('save', next => {
|
||||
next();
|
||||
});
|
||||
|
||||
ArticleSchema.methods.genSlug = () => this.title.toLowerCase().replace(/\W+/g, '-');
|
||||
|
||||
export default mongoose.model('Article', ArticleSchema);
|
||||
|
18
src/routes/cms/index.svelte
Normal file
18
src/routes/cms/index.svelte
Normal file
@ -0,0 +1,18 @@
|
||||
<script context="module">
|
||||
export async function preload(page, session)
|
||||
{
|
||||
if (!session.user) {
|
||||
return this.redirect(302, '/cms/login');
|
||||
}
|
||||
return { user: session.user };
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="content">
|
||||
<h1>HowFeed Publisher</h1>
|
||||
<form method="POST" action="/cms/article">
|
||||
|
||||
<textarea name="content"></textarea>
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
</div>
|
@ -1,7 +1,3 @@
|
||||
<script>
|
||||
let username, password;
|
||||
</script>
|
||||
|
||||
<style>
|
||||
input {
|
||||
display: block;
|
||||
@ -26,8 +22,8 @@
|
||||
<div class="content">
|
||||
<h1>Login</h1>
|
||||
<form method="POST" action="/cms/login">
|
||||
<input required type="text" name="username" bind:value={username} placeholder="Username">
|
||||
<input required type="password" name="password" bind:value={password} placeholder="Password">
|
||||
<input required type="text" name="username" placeholder="Username">
|
||||
<input required type="password" name="password" placeholder="Password">
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -84,5 +84,5 @@ express()
|
||||
|
||||
.listen(PORT, err => {
|
||||
if (err) console.log('error', err);
|
||||
console.log('Express server listening');
|
||||
console.log(`Express server listening on port ${PORT}`);
|
||||
});
|
||||
|
1
storage/.gitignore
vendored
1
storage/.gitignore
vendored
@ -1 +0,0 @@
|
||||
*.db
|
@ -1,12 +0,0 @@
|
||||
PRAGMA foreign_keys = ON;
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
username TEXT PRIMARY KEY,
|
||||
password TEXT NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS articles (
|
||||
title TEXT PRIMARY KEY,
|
||||
created_at TEXT NOT NULL,
|
||||
html BLOB NOT NULL,
|
||||
author INTEGER NOT NULL,
|
||||
FOREIGN KEY (author) REFERENCES users (username)
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user