diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..cbdeb84 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "nodebb/lib" +} \ No newline at end of file diff --git a/library.js b/library.js index e914a8c..29ede0c 100644 --- a/library.js +++ b/library.js @@ -1,43 +1,38 @@ 'use strict'; -var meta = require.main.require('./src/meta'); -var user = require.main.require('./src/user'); +const meta = require.main.require('./src/meta'); +const user = require.main.require('./src/user'); -var library = {}; - -library.init = function(params, callback) { - var app = params.router; - var middleware = params.middleware; +const library = module.exports; +library.init = async function (params) { + const { app, middleware } = params; app.get('/admin/plugins/persona', middleware.admin.buildHeader, renderAdmin); app.get('/api/admin/plugins/persona', renderAdmin); - - callback(); }; -library.addAdminNavigation = function(header, callback) { +library.addAdminNavigation = async function (header) { header.plugins.push({ route: '/plugins/persona', icon: 'fa-paint-brush', - name: 'Persona Theme' + name: 'Persona Theme', }); - - callback(null, header); + return header; }; -library.defineWidgetAreas = function(areas, callback) { +library.defineWidgetAreas = async function (areas) { const locations = ['header', 'sidebar', 'footer']; const templates = [ 'categories.tpl', 'category.tpl', 'topic.tpl', 'users.tpl', - 'unread.tpl', 'recent.tpl', 'popular.tpl', 'top.tpl', 'tags.tpl', 'tag.tpl' + 'unread.tpl', 'recent.tpl', 'popular.tpl', 'top.tpl', 'tags.tpl', 'tag.tpl', ]; function capitalizeFirst(str) { - return str.charAt(0).toUpperCase() + str.slice(1) + return str.charAt(0).toUpperCase() + str.slice(1); } - templates.forEach(template => { - locations.forEach(location => { + templates.forEach((template) => { + locations.forEach((location) => { areas.push({ - name: capitalizeFirst(template.split('.')[0]) + ' ' + capitalizeFirst(location), + name: `${capitalizeFirst(template.split('.')[0])} ${capitalizeFirst(location)}`, template: template, location: location, }); @@ -46,16 +41,15 @@ library.defineWidgetAreas = function(areas, callback) { areas = areas.concat([ { - name: "Account Header", - template: "account/profile.tpl", - location: "header" + name: 'Account Header', + template: 'account/profile.tpl', + location: 'header', }, ]); - - callback(null, areas); + return areas; }; -library.getThemeConfig = async function(config) { +library.getThemeConfig = async function (config) { const settings = await meta.settings.get('persona'); config.hideSubCategories = settings.hideSubCategories === 'on'; config.hideCategoryLastPost = settings.hideCategoryLastPost === 'on'; @@ -63,7 +57,7 @@ library.getThemeConfig = async function(config) { return config; }; -function renderAdmin(req, res, next) { +function renderAdmin(req, res) { res.render('admin/plugins/persona', {}); } @@ -74,7 +68,7 @@ library.addUserToTopic = async function (hookData) { const userData = await user.getUserData(hookData.req.user.uid); hookData.templateData.loggedInUser = userData; } else { - hookData.templateData.loggedInUser = { + hookData.templateData.loggedInUser = { uid: 0, username: '[[global:guest]]', picture: user.getDefaultAvatar(), diff --git a/package.json b/package.json index 4f22623..fd61ec2 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,9 @@ "type": "git", "url": "https://github.com/psychobunny/nodebb-theme-persona" }, + "scripts": { + "lint": "eslint ." + }, "keywords": [ "nodebb", "theme", @@ -41,5 +44,10 @@ "dependencies": { "pulling": "^2.0.0", "striptags": "^3.2.0" + }, + "devDependencies": { + "eslint": "^7.32.0", + "eslint-config-nodebb": "^0.0.2", + "eslint-plugin-import": "^2.24.2" } } diff --git a/public/.eslintrc b/public/.eslintrc new file mode 100644 index 0000000..bf4af75 --- /dev/null +++ b/public/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "nodebb/public" +} \ No newline at end of file