user locale, favicon

This commit is contained in:
lesion 2019-07-24 21:26:56 +02:00
parent 96e0a0b57c
commit 4b1aff3862
9 changed files with 51 additions and 28 deletions

View file

@ -2,6 +2,7 @@
"title": "Gancio",
"description": "A shared agenda for local communities",
"favicon" : "../dist/favicon.ico",
"user_locale": "./user_locale.json",
"baseurl": "http://localhost:13120",
"server": {
"host": "localhost",

View file

@ -1,6 +1,10 @@
import acceptLanguage from 'accept-language'
export default function ({ req, app, store }) {
if (process.server) {
const lang = req.acceptsLanguages('en', 'it')
const acceptedLanguages = req.headers['accept-language']
const supportedLanguages = ['en', 'it']
acceptLanguage.languages(supportedLanguages)
const lang = acceptLanguage.get(acceptedLanguages)
store.commit('setLocale', lang || 'it')
app.i18n.locale = store.state.locale
}

View file

@ -13,9 +13,9 @@ module.exports = {
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
},
dev: (process.env.NODE_ENV !== 'production'),
// serverMiddleware: [
// { path: '/api', handler: '@/server/api/index.js' }
// ],
serverMiddleware: [
{ path: '/api', handler: '~/server/api/index.js' }
],
server: conf.server,
@ -81,21 +81,21 @@ module.exports = {
** Build configuration
*/
build: {
optimization: {
splitChunks: {
cacheGroups: {
element: {
test: /[\\/]node_modules[\\/](element-ui)[\\/]/,
name: 'element-ui',
chunks: 'all'
}
}
}
},
// optimization: {
// splitChunks: {
// cacheGroups: {
// element: {
// test: /[\\/]node_modules[\\/](element-ui)[\\/]/,
// name: 'element-ui',
// chunks: 'all'
// }
// }
// }
// },
transpile: [/^element-ui/, /^vue-awesome/],
splitChunks: {
layouts: true
},
// splitChunks: {
// layouts: true
// },
cache: true,
}
}

View file

@ -4,9 +4,11 @@
"description": "A shared agenda for local communities",
"author": "lesion",
"scripts": {
"dev:nuxt": "cross-env NODE_ENV=development nuxt dev",
"dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server",
"build": "nuxt build",
"start": "cross-env NODE_ENV=production node server/cli.js",
"start:nuxt": "cross-env NODE_ENV=development nuxt start",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"doc": "cd docs && bundle exec jekyll b",
"precommit": "npm run lint",
@ -38,6 +40,7 @@
"dependencies": {
"@nuxtjs/auth": "^4.6.5",
"@nuxtjs/axios": "^5.5.3",
"accept-language": "^3.0.18",
"axios": "^0.19.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",

View file

@ -102,7 +102,9 @@ export default {
try {
const [ id, start_datetime ] = params.id.split('_')
const event = await $axios.$get(`/event/${id}`)
event.start_datetime = start_datetime*1000
event.start_datetime = start_datetime ? start_datetime*1000 : event.start_datetime*1000
event.end_datetime = event.end_datetime*1000
// event.start_datetime = start_datetime ? start_datetime*1000 : event.start
return { event, id }
} catch(e) {
error({ statusCode: 404, message: 'Event not found'})

View file

@ -2,17 +2,21 @@ import Vue from 'vue'
import VueI18n from 'vue-i18n'
import it from '../locales/it.js'
import en from '../locales/en.js'
import merge from 'lodash/merge'
Vue.use(VueI18n)
export default ({ app, store }) => {
export default async ({ app, store }) => {
// Set i18n instance on app
// This way we can use it in middleware and pages asyncData/fetch
const user_locale = await app.$axios.$get('/settings/user_locale')
app.i18n = new VueI18n({
locale: store.state.locale,
fallbackLocale: 'it',
messages: {
it, en
it: merge(it, user_locale),
en: merge(en, user_locale)
}
})
}

View file

@ -100,8 +100,8 @@ const eventController = {
order: [ [Comment, 'id', 'DESC'] ]
})
event.start_datetime = event.start_datetime*1000
event.end_datetime = event.end_datetime*1000
// event.start_datetime = event.start_datetime*1000
// event.end_datetime = event.end_datetime*1000
if (event && (event.is_visible || is_admin)) {
res.json(event)

View file

@ -1,6 +1,13 @@
const Mastodon = require('mastodon-api')
const { setting: Setting } = require('../models')
const config = require('config')
const path = require('path')
const fs = require('fs')
let user_locale_path = false
if (config.user_locale && fs.existsSync(path.resolve(config.user_locale))) {
user_locale_path = path.resolve(config.user_locale)
}
const settingsController = {
settings: { initialized: false },
@ -38,11 +45,13 @@ const settingsController = {
},
async getUserLocale(req, res) {
// console.error(res)
console.error(user_locale_path)
// load user locale specified in configuration
// res.json({ about: 'dentro user locale' })
// res.sendStatus(200)
return false
if (user_locale_path) {
res.json(require(user_locale_path))
} else {
res.json({})
}
},
async setRequest(req, res) {

View file

@ -14,7 +14,7 @@ const settingsController = require('./controller/settings')
const storage = require('./storage')
const upload = multer({ storage })
const api = express.Router()
const api = express()
api.use(cookieParser())
api.use(bodyParser.urlencoded({ extended: false }))
api.use(bodyParser.json())