-
+
+
+
{#if !$session.user}
{:else}
diff --git a/src/models/article.js b/src/models/article.js
index cbe5bb1..b160fdc 100644
--- a/src/models/article.js
+++ b/src/models/article.js
@@ -1,4 +1,5 @@
import mongoose from 'mongoose';
+import mongoose_fuzzy_searching from 'mongoose-fuzzy-searching';
const { Schema } = mongoose;
const ArticleSchema = new Schema({
@@ -28,13 +29,18 @@ const ArticleSchema = new Schema({
ArticleSchema.methods.genSlug = title => title.toLowerCase().replace(/\W+/g, '-');
-ArticleSchema.pre('save', function (next) {
- var article = this;
- // only gen the slug if title has been modified (or is new)
- if (!article.isModified('title')) return next();
+ArticleSchema.plugin(mongoose_fuzzy_searching, {
+ fields: ['html', 'title'],
+ middlewares: {
+ preSave: function () {
+ var article = this;
+ // only gen the slug if title has been modified (or is new)
+ if (!article.isModified('title'))
+ return;
- article.slug = article.genSlug(article.title);
- next();
+ article.slug = article.genSlug(article.title);
+ }
+ }
});
export default mongoose.model('Article', ArticleSchema);
diff --git a/src/routes/cms/create.svelte b/src/routes/cms/create.svelte
index 11a7b4b..b4f82e3 100644
--- a/src/routes/cms/create.svelte
+++ b/src/routes/cms/create.svelte
@@ -83,7 +83,7 @@
async function addCategory()
{
let name = prompt('Enter a category name');
- if (name) {
+ if (name !== null) {
const res = await fetch('/cms/category', {
method: 'POST',
headers: {
@@ -92,8 +92,13 @@
},
body: JSON.stringify({ name })
});
- categories = await res.json();
- category = categories.filter(c => c.name === name)[0].slug;
+ const json = await res.json();
+ if (res.status === 200) {
+ categories = json;
+ category = categories.filter(c => c.name === name)[0].slug;
+ } else {
+ alert(`Error ${res.status}: ${json.message}`);
+ }
}
}
diff --git a/src/routes/contact.svelte b/src/routes/contact.svelte
index 4b84821..7c3bf24 100644
--- a/src/routes/contact.svelte
+++ b/src/routes/contact.svelte
@@ -36,7 +36,7 @@
James N. Shiffer
Webmaster
FemboyFinancial Holdings Co., Ltd. (USA LLC)
-
webmaster@femboyfashion.com.hk
+
webmaster@howfeed.biz
diff --git a/src/routes/search/[query].svelte b/src/routes/search/[query].svelte
new file mode 100644
index 0000000..3d1efed
--- /dev/null
+++ b/src/routes/search/[query].svelte
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+ Search Results for: {query} | HOWFEED.BIZ
+
+
+
+
diff --git a/src/routes/search/index.json.js b/src/routes/search/index.json.js
new file mode 100644
index 0000000..080b2d4
--- /dev/null
+++ b/src/routes/search/index.json.js
@@ -0,0 +1,20 @@
+import Article from '../../models/article.js';
+
+export async function get(req, res)
+{
+ const { query } = req.query;
+ if (!query) {
+ res.writeHead(422, {
+ 'Content-Type': 'application/json'
+ });
+ res.end(JSON.stringify({
+ message: `No search query provided`
+ }));
+ return;
+ }
+ const results = await Article.fuzzySearch(query);
+ res.writeHead(200, {
+ 'Content-Type': 'application/json'
+ });
+ res.end(JSON.stringify(results));
+}
diff --git a/src/routes/search/index.svelte b/src/routes/search/index.svelte
new file mode 100644
index 0000000..44e8bee
--- /dev/null
+++ b/src/routes/search/index.svelte
@@ -0,0 +1,18 @@
+
+
+
+
+
+
Search Results
+
You haven't entered any search terms.
+
+
+
diff --git a/static/global.css b/static/global.css
index 6ef090f..8806067 100644
--- a/static/global.css
+++ b/static/global.css
@@ -115,6 +115,7 @@ div.article-meta {
div.background {
background: url('/cityscape.jpg') no-repeat center;
background-size: cover;
+ background-attachment: fixed;
position: fixed;
height: 24rem;
width: 100%;