More tweaks and fixes

Remove accidental debug statement in login page
This commit is contained in:
Jonatan Nilsson 2019-10-02 17:40:32 +00:00
parent bcf5e90857
commit 97c64003a7
17 changed files with 140 additions and 52 deletions

View file

@ -136,7 +136,7 @@ const Article = bookshelf.createModel({
.fetchPage({ .fetchPage({
pageSize: 10, pageSize: 10,
page: page, page: page,
withRelated: ['files', 'media', 'banner'], withRelated: ['files', 'media', 'banner', 'parent'],
}) })
}, },
}) })

View file

@ -20,8 +20,6 @@ export default class AuthHelper {
}) })
.fetch({ require: true }) .fetch({ require: true })
console.log(ctx.request.body.password, staff.get('password'))
await this.Staff.compare(ctx.request.body.password, staff.get('password')) await this.Staff.compare(ctx.request.body.password, staff.get('password'))
} catch (err) { } catch (err) {
if (err.message === 'EmptyResponse' || err.message === 'PasswordMismatch') { if (err.message === 'EmptyResponse' || err.message === 'PasswordMismatch') {

View file

@ -18,7 +18,7 @@ export default class Resizer {
withoutEnlargement: true, withoutEnlargement: true,
}) })
.jpeg({ .jpeg({
quality: 80, quality: 90,
}) })
.toFile(output) .toFile(output)
.then(() => output) .then(() => output)
@ -33,7 +33,7 @@ export default class Resizer {
withoutEnlargement: true, withoutEnlargement: true,
}) })
.jpeg({ .jpeg({
quality: 80, quality: 90,
}) })
.toFile(output) .toFile(output)
.then(() => output) .then(() => output)
@ -43,8 +43,12 @@ export default class Resizer {
let output = this.Media.getSubUrl(input, 'large') let output = this.Media.getSubUrl(input, 'large')
return this.sharp(input) return this.sharp(input)
.resize(1280, 1280, {
fit: sharp.fit.inside,
withoutEnlargement: true,
})
.jpeg({ .jpeg({
quality: 80, quality: 90,
}) })
.toFile(output) .toFile(output)
.then(() => output) .then(() => output)

View file

@ -1,3 +1,4 @@
import bookshelf from '../bookshelf.mjs' import bookshelf from '../bookshelf.mjs'
import Media from '../media/model.mjs' import Media from '../media/model.mjs'
import Staff from '../staff/model.mjs' import Staff from '../staff/model.mjs'
@ -37,6 +38,9 @@ const Page = bookshelf.createModel({
children() { children() {
return this.hasManyFiltered(Page, 'children', 'parent_id') return this.hasManyFiltered(Page, 'children', 'parent_id')
.query(qb => {
qb.orderBy('name', 'ASC')
})
}, },
news() { news() {
@ -65,6 +69,7 @@ const Page = bookshelf.createModel({
return this.query(qb => { return this.query(qb => {
qb.where({ parent_id: null }) qb.where({ parent_id: null })
qb.select(['id', 'name', 'path']) qb.select(['id', 'name', 'path'])
qb.orderBy('name', 'ASC')
}).fetchAll({ withRelated: ['children'] }) }).fetchAll({ withRelated: ['children'] })
}, },
}) })

View file

@ -18,7 +18,7 @@ export default class PageRoutes {
filter.parent_id = null filter.parent_id = null
} }
ctx.body = await this.Page.getAll(ctx, filter, ctx.state.filter.includes) ctx.body = await this.Page.getAll(ctx, filter, ctx.state.filter.includes, 'name')
} }
/** GET: /api/pages/:id */ /** GET: /api/pages/:id */

View file

@ -10,20 +10,20 @@ const body = readFileSync('./public/index.html').toString()
const bodyTemplate = dot.template(body) const bodyTemplate = dot.template(body)
const frontend = config.get('frontend:url') const frontend = config.get('frontend:url')
function mapArticle(x) { function mapArticle(trim = false, x, includeBanner = false, includeFiles = true) {
return { return {
id: x.id, id: x.id,
created_at: x.created_at,
published_at: x.published_at, published_at: x.published_at,
path: x.path, path: x.path,
description: x.description, description: x.description,
name: x.name, name: x.name,
media: x.media && ({ media: x.media && ({
link: !trim && x.media.link || null,
large_url: x.media.large_url, large_url: x.media.large_url,
medium_url: x.media.medium_url, medium_url: x.media.medium_url,
small_url: x.media.small_url, small_url: x.media.small_url,
}) || null, }) || null,
banner: x.banner && ({ banner: x.banner && includeBanner && ({
large_url: x.banner.large_url, large_url: x.banner.large_url,
medium_url: x.banner.medium_url, medium_url: x.banner.medium_url,
small_url: x.banner.small_url, small_url: x.banner.small_url,
@ -33,16 +33,20 @@ function mapArticle(x) {
name: x.parent.name, name: x.parent.name,
path: x.parent.path, path: x.parent.path,
}), }),
files: x.files && x.files.map(f => ({ files: x.files && includeFiles && x.files.map(f => ({
filename: f.filename, filename: f.filename,
url: f.url, url: f.url,
magnet: f.magnet, magnet: f.magnet,
meta: f.meta.torrent && ({ meta: f.meta.torrent && ({
torrent: { torrent: {
files: f.meta.torrent.files.map(tf => ({ name: f.meta.torrent.name,
files: f.meta.torrent.files.map(tf => {
if (trim && f.meta.torrent.files.length > 4) return 1
return {
name: tf.name, name: tf.name,
size: tf.size, size: tf.size,
})), }
}),
}, },
}) || {}, }) || {},
})) || [], })) || [],
@ -57,6 +61,7 @@ function mapPage(x) {
description: x.description, description: x.description,
name: x.name, name: x.name,
media: x.media && ({ media: x.media && ({
link: x.media.link,
large_url: x.media.large_url, large_url: x.media.large_url,
medium_url: x.media.medium_url, medium_url: x.media.medium_url,
small_url: x.media.small_url, small_url: x.media.small_url,
@ -92,7 +97,7 @@ export async function serveIndex(ctx, path) {
)) ))
featured = await Article.getFeatured(['files', 'media', 'banner']) featured = await Article.getFeatured(['files', 'media', 'banner'])
if (featured) { if (featured) {
featured = mapArticle(featured.toJSON()) featured = mapArticle(true, featured.toJSON(), true, false)
} }
if (path === '/') { if (path === '/') {
@ -109,7 +114,7 @@ export async function serveIndex(ctx, path) {
current: { title: 'Page 1' }, current: { title: 'Page 1' },
} }
} }
data = data.toJSON().map(mapArticle) data = data.toJSON().map(mapArticle.bind(null, true))
} else if (path.startsWith('/article/') || path.startsWith('/page/')) { } else if (path.startsWith('/article/') || path.startsWith('/page/')) {
let id = path.split('/')[2] let id = path.split('/')[2]
if (id) { if (id) {
@ -117,7 +122,7 @@ export async function serveIndex(ctx, path) {
if (path.startsWith('/article/')) { if (path.startsWith('/article/')) {
found = await Article.getSingle(id, ['media', 'parent', 'banner', 'files'], false, null, true) found = await Article.getSingle(id, ['media', 'parent', 'banner', 'files'], false, null, true)
if (found) { if (found) {
found = mapArticle(found.toJSON()) found = mapArticle(false, found.toJSON())
} }
data = found data = found
} else { } else {

View file

@ -56,7 +56,7 @@ const AdminPages = {
return [ return [
m('tr', [ m('tr', [
m('td', [ m('td', [
page.parent_id ? m('span.subpage', '| >') : null, page.parent_id ? m('span.subpage', ' - ') : null,
m(m.route.Link, { href: '/admin/pages/' + page.id }, page.name), m(m.route.Link, { href: '/admin/pages/' + page.id }, page.name),
]), ]),
m('td', m(m.route.Link, { href: '/page/' + page.path }, '/page/' + page.path)), m('td', m(m.route.Link, { href: '/page/' + page.path }, '/page/' + page.path)),

View file

@ -58,6 +58,19 @@ const Article = {
}, },
view: function(vnode) { view: function(vnode) {
var deviceWidth = window.innerWidth
var imagePath = ''
if (this.article.media) {
var pixelRatio = window.devicePixelRatio || 1
if ((deviceWidth < 800 && pixelRatio <= 1)
|| (deviceWidth < 600 && pixelRatio > 1)) {
imagePath = this.article.media.medium_url
} else {
imagePath = this.article.media.large_url
}
}
return ( return (
this.loading ? this.loading ?
m('div.loading-spinner') m('div.loading-spinner')
@ -67,8 +80,8 @@ const Article = {
this.article.media this.article.media
? m('a.cover', { ? m('a.cover', {
rel: 'noopener', rel: 'noopener',
href: this.article.media.url, href: this.article.media.link,
}, m('img', { src: this.article.media.medium_url, alt: 'Cover image for ' + this.article.name })) }, m('img', { src: imagePath, alt: 'Cover image for ' + this.article.name }))
: null, : null,
this.article.description ? m.trust(this.article.description) : null, this.article.description ? m.trust(this.article.description) : null,
(this.article.files && this.article.files.length (this.article.files && this.article.files.length

View file

@ -17,7 +17,7 @@ article.article {
} }
.cover { .cover {
margin: 0 -10px 20px; margin: 0 0 20px;
} }
.admin-actions { .admin-actions {
@ -44,6 +44,14 @@ article.article {
} }
} }
fileinfo {
font-size: 0.8em;
ul {
padding-left: 0;
}
}
.opencomments { .opencomments {
border: none; border: none;
align-self: center; align-self: center;

View file

@ -15,6 +15,7 @@ footer {
align-items: center; align-items: center;
font-size: 11px; font-size: 11px;
font-weight: bold; font-weight: bold;
padding-right: 20px;
a { a {
text-decoration: none; text-decoration: none;
@ -30,7 +31,12 @@ footer {
ul { ul {
margin: 2px 0 0; margin: 2px 0 0;
display: flex; display: flex;
padding: 0; flex-wrap: wrap;
padding: 0 0 10px;
justify-content: center;
border-bottom: 1px solid white;
margin-bottom: 10px;
min-width: 300px;
li { li {
padding: 2px 5px; padding: 2px 5px;
@ -45,6 +51,7 @@ footer {
background-size: contain; background-size: contain;
width: 119px; width: 119px;
height: 150px; height: 150px;
flex: 0 0 119px;
} }
.meta { .meta {
@ -107,6 +114,23 @@ only screen and ( min-resolution: 2dppx) {
} }
@media screen and (max-width: 480px){ @media screen and (max-width: 480px){
footer {
flex-direction: column;
align-items: center;
.footer-logo {
margin-top: 20px;
}
.sitemap {
padding-right: 0px;
ul {
align-self: stretch;
}
}
}
footer .sitemap a.root, footer .sitemap a.root,
footer .sitemap a.child { footer .sitemap a.child {
padding: 9px 10px; padding: 9px 10px;

View file

@ -17,8 +17,6 @@ const Frontpage = {
this.featured = window.__nfpfeatured this.featured = window.__nfpfeatured
} }
console.log(this.featured)
if (window.__nfpdata if (window.__nfpdata
&& window.__nfplinks) { && window.__nfplinks) {
this.links = window.__nfplinks this.links = window.__nfplinks
@ -85,6 +83,7 @@ const Frontpage = {
}, },
view: function(vnode) { view: function(vnode) {
console.log(this.articles)
var deviceWidth = window.innerWidth var deviceWidth = window.innerWidth
var bannerPath = '' var bannerPath = ''

View file

@ -87,7 +87,13 @@ frontpage {
} }
.asunaside { .asunaside {
display: none; display: block;
width: 200px;
height: 480px;
background-size: contain;
background-repeat: no-repeat;
background-position: top left;
align-self: center;
} }
} }
@ -98,7 +104,7 @@ frontpage {
} }
} }
@media screen and (max-width: 800px){ @media screen and (max-width: 900px){
frontpage { frontpage {
flex-direction: column; flex-direction: column;
} }
@ -113,24 +119,12 @@ frontpage {
} }
} }
@media screen and (min-width: 800px){ .daymode frontpage .asunaside {
frontpage .asunaside {
display: block;
width: 200px;
height: 480px;
background-size: contain;
background-repeat: no-repeat;
background-position: top left;
align-self: center;
}
.daymode frontpage .asunaside {
background-image: url("/assets/img/asuna_frontpage.jpg"); background-image: url("/assets/img/asuna_frontpage.jpg");
} }
.darkmodeon frontpage .asunaside { .darkmodeon frontpage .asunaside {
background-image: url("/assets/img/dark_asuna_frontpage.jpg"); background-image: url("/assets/img/dark_asuna_frontpage.jpg");
}
} }
@media screen and (max-width: 480px){ @media screen and (max-width: 480px){

View file

@ -83,10 +83,11 @@ const Page = {
view: function(vnode) { view: function(vnode) {
var deviceWidth = window.innerWidth var deviceWidth = window.innerWidth
var pixelRatio = window.devicePixelRatio || 1
var bannerPath = '' var bannerPath = ''
var imagePath = ''
if (this.page && this.page.banner) { if (this.page && this.page.banner) {
var pixelRatio = window.devicePixelRatio || 1
if (deviceWidth < 400 && pixelRatio <= 1) { if (deviceWidth < 400 && pixelRatio <= 1) {
bannerPath = this.page.banner.small_url bannerPath = this.page.banner.small_url
} else if ((deviceWidth < 800 && pixelRatio <= 1) } else if ((deviceWidth < 800 && pixelRatio <= 1)
@ -97,6 +98,15 @@ const Page = {
} }
} }
if (this.page && this.page.media) {
if ((deviceWidth < 1000 && pixelRatio <= 1)
|| (deviceWidth < 800 && pixelRatio > 1)) {
imagePath = this.page.media.medium_url
} else {
imagePath = this.page.media.large_url
}
}
return ( return (
this.loading ? this.loading ?
m('div.loading-spinner') m('div.loading-spinner')
@ -116,7 +126,7 @@ const Page = {
: null, : null,
this.page.description this.page.description
? m('.fr-view', [ ? m('.fr-view', [
this.page.media ? m('img.page-cover', { src: this.page.media.medium_url, alt: 'Cover image for ' + this.page.name } ) : null, imagePath ? m('a', { href: this.page.media.link}, m('img.page-cover', { src: imagePath, alt: 'Cover image for ' + this.page.name } )) : null,
m.trust(this.page.description), m.trust(this.page.description),
this.news.length && this.page.description this.news.length && this.page.description
? m('aside.news', [ ? m('aside.news', [
@ -133,7 +143,7 @@ const Page = {
]) ])
: this.news.length : this.news.length
? m('aside.news.single', [ ? m('aside.news.single', [
this.page.media ? m('img.page-cover', { src: this.page.media.medium_url, alt: 'Cover image for ' + this.page.name } ) : null, imagePath ? m('a', { href: this.page.media.link}, m('img.page-cover', { src: imagePath, alt: 'Cover image for ' + this.page.name } )) : null,
m('h4', 'Latest posts under ' + this.page.name + ':'), m('h4', 'Latest posts under ' + this.page.name + ':'),
this.loadingnews ? m('div.loading-spinner') : this.news.map(function(article) { this.loadingnews ? m('div.loading-spinner') : this.news.map(function(article) {
return m(Newsentry, article) return m(Newsentry, article)

View file

@ -144,6 +144,7 @@ aside.news {
border-top: none; border-top: none;
margin-top: 0; margin-top: 0;
align-self: flex-start; align-self: flex-start;
margin: 0;
& > h4 { & > h4 {
padding: 0 5px 5px; padding: 0 5px 5px;
@ -171,6 +172,10 @@ aside.news {
border-bottom: 1px solid $border; border-bottom: 1px solid $border;
padding: 0 0 5px; padding: 0 0 5px;
} }
article.page .news.single .page-cover {
margin: 0 0 20px;
}
} }
@media screen and (max-width: 360px){ @media screen and (max-width: 360px){

View file

@ -84,6 +84,10 @@ fileinfo {
} }
} }
.trimmed {
padding: 3px 0 5px 25px;
}
ul { ul {
margin: 10px 0; margin: 10px 0;
padding-left: 0; padding-left: 0;
@ -166,9 +170,13 @@ newsitem {
font-size: 11px; font-size: 11px;
color: $meta-fg; color: $meta-fg;
font-weight: bold; font-weight: bold;
display: flex;
align-items: flex-end;
padding: 10px 0; padding: 10px 0;
a {
color: $secondary-dark-bg;
margin: 0 5px;
text-decoration: none;
}
} }
} }
@ -255,6 +263,10 @@ pages {
.entrymeta { .entrymeta {
color: $dark_meta-fg; color: $dark_meta-fg;
a {
color: $dark_secondary-dark-bg;
}
} }
} }

View file

@ -57,7 +57,10 @@ const Fileinfo = {
: null, : null,
m('span', this.getTitle(vnode)), m('span', this.getTitle(vnode)),
]), ]),
vnode.attrs.file.meta.torrent && !vnode.attrs.slim vnode.attrs.file.meta.torrent
&& !vnode.attrs.slim
&& vnode.attrs.file.meta.torrent.files.length > 1
&& (!vnode.attrs.trim || vnode.attrs.file.meta.torrent.files.length <= 4)
? m('ul', vnode.attrs.file.meta.torrent.files.map(function(file) { ? m('ul', vnode.attrs.file.meta.torrent.files.map(function(file) {
return m('li', [ return m('li', [
file.name + ' ', file.name + ' ',
@ -65,6 +68,9 @@ const Fileinfo = {
]) ])
})) }))
: null, : null,
vnode.attrs.trim && vnode.attrs.file.meta.torrent.files.length > 4
? m('div.trimmed', '...' + vnode.attrs.file.meta.torrent.files.length + ' files...')
: null,
]) ])
}, },
} }

View file

@ -22,10 +22,15 @@ const Newsitem = {
: null), : null),
(vnode.attrs.files && vnode.attrs.files.length (vnode.attrs.files && vnode.attrs.files.length
? vnode.attrs.files.map(function(file) { ? vnode.attrs.files.map(function(file) {
return m(Fileinfo, { file: file }) return m(Fileinfo, { file: file, trim: true })
}) })
: null), : null),
m('span.entrymeta', 'Posted ' + vnode.attrs.published_at.replace('T', ' ').split('.')[0]), m('span.entrymeta', [
'Posted ',
(vnode.attrs.parent ? 'in' : ''),
(vnode.attrs.parent ? m(m.route.Link, { href: '/page/' + vnode.attrs.parent.path }, vnode.attrs.parent.name) : null),
'at ' + (vnode.attrs.published_at.replace('T', ' ').split('.')[0]).substr(0, 16),
]),
]), ]),
]), ]),
]) ])