This repository has been archived by the owner on Aug 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yunus Gürlek
authored and
Yunus Gürlek
committed
Jun 24, 2023
1 parent
848462c
commit 3bb9937
Showing
25 changed files
with
389 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const EDITORS_PICK_WRITING_COUNT = 5; | ||
|
||
const Writing = require('../../../models/writing/Writing'); | ||
|
||
module.exports = (req, res) => { | ||
const language = res.locals.lang; | ||
|
||
Writing.findWritingsByFiltersAndFormatByLanguage({ | ||
limit: EDITORS_PICK_WRITING_COUNT, | ||
label: 'editors_pick', | ||
type: 'blog', | ||
do_not_load_content: true, | ||
do_not_load_blog: true, | ||
do_not_load_writer: true | ||
}, language, (err, data) => { | ||
if (err) return res.json({ success: false, error: err } ); | ||
|
||
req.session.navbar_data_editors_pick = data.writings; | ||
req.session.navbar_last_update_time = (new Date).getTime(); | ||
|
||
return res.json({ success: true, writings: data.writings }); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const EXCLUSIVE_WRITING_COUNT = 5; | ||
|
||
const Writing = require('../../../models/writing/Writing'); | ||
|
||
module.exports = (req, res) => { | ||
const language = res.locals.lang; | ||
|
||
Writing.findWritingsByFiltersAndFormatByLanguage({ | ||
limit: EXCLUSIVE_WRITING_COUNT, | ||
label: 'exclusive', | ||
type: 'blog', | ||
do_not_load_content: true, | ||
do_not_load_blog: true, | ||
do_not_load_writer: true | ||
}, language, (err, data) => { | ||
if (err) return res.json({ success: false, error: err } ); | ||
|
||
req.session.navbar_data_exclusive = data.writings; | ||
req.session.navbar_last_update_time = (new Date).getTime(); | ||
|
||
return res.json({ success: true, writings: data.writings }); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const Tag = require('../../../models/tag/Tag'); | ||
|
||
module.exports = (req, res) => { | ||
const language = res.locals.lang; | ||
|
||
Tag.findTagsByFiltersAndFormatByLanguage({}, language, (err, data) => { | ||
if (err) return res.json({ success: false, error: err } ); | ||
|
||
req.session.navbar_data_tags = data.tags; | ||
req.session.navbar_last_update_time = (new Date).getTime(); | ||
|
||
return res.json({ success: true, tags: data.tags }); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,19 @@ | ||
const EDITORS_PICK_WRITING_COUNT = 5; | ||
const EXCLUSIVE_WRITING_COUNT = 5; | ||
const FIVE_MINS_IN_MS = 5 * 60 * 1000; | ||
|
||
const Tag = require('../models/tag/Tag'); | ||
const Writing = require('../models/writing/Writing'); | ||
|
||
module.exports = (req, res, next) => { | ||
const language = res.locals.lang; | ||
|
||
if ( | ||
req.session && | ||
req.session.navbar_data && | ||
req.session.navbar_data_editors_pick && | ||
req.session.navbar_data_tags && | ||
req.session.navbar_data_exclusive && | ||
req.session.navbar_last_update_time && | ||
(new Date).getTime() - req.session.navbar_last_update_time < FIVE_MINS_IN_MS | ||
) { | ||
const navbar = JSON.parse(req.session.navbar_data); | ||
|
||
res.locals.tags = navbar.tags; | ||
res.locals.editors_pick = navbar.editors_pick; | ||
res.locals.exclusive = navbar.exclusive; | ||
|
||
return next(); | ||
} else { | ||
Tag.findTagsByFiltersAndFormatByLanguage({}, language, (err, tags_data) => { | ||
if (err) return res.redirect('/error?message=' + err); | ||
|
||
Writing.findWritingsByFiltersAndFormatByLanguage({ | ||
limit: EDITORS_PICK_WRITING_COUNT, | ||
label: 'editors_pick', | ||
type: 'blog', | ||
do_not_load_content: true, | ||
do_not_load_blog: true, | ||
do_not_load_writer: true | ||
}, language, (err, editors_pick_data) => { | ||
if (err) return res.redirect('/error?message=' + err); | ||
|
||
Writing.findWritingsByFiltersAndFormatByLanguage({ | ||
limit: EXCLUSIVE_WRITING_COUNT, | ||
label: 'exclusive', | ||
type: 'blog', | ||
do_not_load_content: true, | ||
do_not_load_blog: true, | ||
do_not_load_writer: true | ||
}, language, (err, exclusive_data) => { | ||
if (err) return res.redirect('/error?message=' + err); | ||
|
||
req.session.navbar_data = JSON.stringify({ | ||
tags: tags_data.tags, | ||
editors_pick: editors_pick_data.writings, | ||
exclusive: exclusive_data.writings | ||
}); | ||
req.session.navbar_last_update_time = (new Date).getTime(); | ||
|
||
res.locals.tags = tags_data.tags; | ||
res.locals.editors_pick = editors_pick_data.writings; | ||
res.locals.exclusive = exclusive_data.writings; | ||
|
||
return next(); | ||
}); | ||
}); | ||
}); | ||
res.locals.navbar_loaded = true; | ||
res.locals.editors_pick = req.session.navbar_data_editors_pick; | ||
res.locals.tags = req.session.navbar_data_tags; | ||
res.locals.exclusive = req.session.navbar_data_exclusive; | ||
} | ||
|
||
return next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
let MONTHS; | ||
const NEW_WRITING_LOAD_SCROLL_DISTANCE = 300; | ||
const WRITING_COUNT = 5; | ||
|
||
let blog; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
let MONTHS; | ||
const NEW_WRITING_LOAD_SCROLL_DISTANCE = 300; | ||
const WRITING_COUNT = 5; | ||
|
||
let writing; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const COOKIE_PREFIX = 'node101-'; | ||
const DEFAULT_COOKIE_MAX_AGE = 5 * 60 * 1000; | ||
|
||
getCookie = function (cookieName) { | ||
const name = COOKIE_PREFIX + cookieName + '='; | ||
const cookies = decodeURIComponent(document.cookie); | ||
const cookieArray = cookies.split(';').map(each => each.trim()); | ||
let findCookie = cookieArray.find(each => each.indexOf(name) == 0); | ||
if (findCookie) | ||
findCookie = JSON.parse(findCookie.substring(name.length)); | ||
|
||
return findCookie; | ||
}; | ||
|
||
setCookie = function (cookieName, cookieValue, cookieMaxAge) { | ||
if (!cookieMaxAge || !Number.isInteger(cookieMaxAge) || cookieMaxAge < 0) | ||
cookieMaxAge = DEFAULT_COOKIE_MAX_AGE; | ||
|
||
document.cookie = `${COOKIE_PREFIX}${cookieName}=${JSON.stringify(cookieValue)}; Max-Age=${cookieMaxAge}`; | ||
}; | ||
|
||
deleteCookie = function (cookieName) { | ||
setCookie(cookieName, '', 0); | ||
}; |
Oops, something went wrong.