Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewCallis committed Apr 14, 2023
1 parent cab1f8f commit 95e9275
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 19 deletions.
13 changes: 10 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"plugin:node/recommended",
"plugin:optimize-regex/all",
"plugin:ramda/recommended",
"plugin:security/recommended"
"plugin:security/recommended",
"plugin:sonarjs/recommended"
],
"plugins": [
"anti-trojan-source",
Expand All @@ -21,6 +22,7 @@
"optimize-regex",
"ramda",
"security",
"sonarjs",
"xss"
],
"env": {
Expand All @@ -37,10 +39,12 @@
},
"rules": {
"anti-trojan-source/no-bidi": "error",
"ava/no-only-test": 0,
"camelcase": 0,
"consistent-return": ["warn", { "treatUndefinedAsUnspecified": false }],
"eslint-comments/no-use": 0,
"filenames/match-regex": 0,
"global-require": 0,
"import/no-commonjs": 0,
"import/no-dynamic-require": 0,
"import/no-extraneous-dependencies": [
"error", {
Expand Down Expand Up @@ -76,9 +80,12 @@
"node/no-unpublished-require": 0,
"object-curly-newline": 0,
"optimize-regex/optimize-regex": "warn",
"prettier/prettier": 0,
"security/detect-non-literal-fs-filename": 0,
"security/detect-non-literal-require": 0,
"security/detect-object-injection": 0
"security/detect-object-injection": 0,
"sonarjs/cognitive-complexity": 0,
"sonarjs/no-duplicate-string": 0
},
"settings": {
"jsdoc": {
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).

## [5.2.1](https://github.com/uttori/uttori-wiki/compare/v5.2.0...v5.2.1) - 2023-04-13

- 🧹 Regenerate docs and readme with new updates.
- 🛠 Clean up some types that were outdated.
- 🛠 Clean up a `forEach` use that should have been `for of`.
- 🛠 Clean up an uneeded check of `document`.

## [5.2.0](https://github.com/uttori/uttori-wiki/compare/v5.1.0...v5.2.0) - 2023-04-12

- 🧰 Add support for per route middleware through the configuration.
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,25 @@ const config = {
historyRestoreRoute: (request, response, next) => { ... },
notFoundRoute: (request, response, next) => { ... },
saveValidRoute: (request, response, next) => { ... },

// Custom per route middleware, in the order they should be used
routeMiddleware: {
home: [],
tagIndex: [],
tag: [],
search: [],
notFound: [],
create: [],
saveNew: [],
preview: [],
edit: [],
delete: [],
historyIndex: [],
historyDetail: [],
historyRestore: [],
save: [],
detail: [],
},
};

module.exports = config;
Expand Down
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
| [historyRestoreRoute] | <code>function</code> | | A replacement route handler for the history restore route. |
| [notFoundRoute] | <code>function</code> | | A replacement route handler for the 404 not found route. |
| [saveValidRoute] | <code>function</code> | | A replacement route handler for the save valid route. |
| [routeMiddleware] | <code>object</code> | | A collection of middleware for each route. |
| plugins | <code>Array</code> | | Collection of Uttori Plugins. Storage Plugins should come before other plugins. |
| [middleware] | <code>Array</code> | | Middleware Configuration to be passed along to Express in the format of ['use', layouts], ['set', 'layout extractScripts', true], ['engine', 'html', ejs.renderFile]. |

20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-security": "^1.7.1",
"eslint-plugin-sonarjs": "^0.19.0",
"eslint-plugin-xss": "^0.1.12",
"express": "^4.18.2",
"express-ejs-layouts": "^2.5.1",
Expand Down
19 changes: 19 additions & 0 deletions rm.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,25 @@ const config = {
historyRestoreRoute: (request, response, next) => { ... },
notFoundRoute: (request, response, next) => { ... },
saveValidRoute: (request, response, next) => { ... },

// Custom per route middleware, in the order they should be used
routeMiddleware: {
home: [],
tagIndex: [],
tag: [],
search: [],
notFound: [],
create: [],
saveNew: [],
preview: [],
edit: [],
delete: [],
historyIndex: [],
historyDetail: [],
historyRestore: [],
save: [],
detail: [],
},
};

module.exports = config;
Expand Down
4 changes: 2 additions & 2 deletions src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ module.exports = function middleware(config) {
// Apply middleware configuration
if (config.middleware && Array.isArray(config.middleware)) {
// console.log('config.middleware', config.middleware);
config.middleware.forEach((item) => {
for (const item of config.middleware) {
const fn = item.shift();
if (fn && app[fn] && typeof app[fn] === 'function') {
debug(`app.${fn}(${JSON.stringify(item)})`);
app[fn].call(app, ...item);
}
});
}
}

// https://expressjs.com/en/4x/api.html#express.static
Expand Down
2 changes: 1 addition & 1 deletion src/wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class UttoriWiki {
let image = '';

if (document) {
description = document && document.excerpt ? document.excerpt : '';
description = document.excerpt ? document.excerpt : '';
if (document.content && !description) {
description = document.content.slice(0, 160);
description = await this.hooks.filter('render-content', description, this);
Expand Down
2 changes: 1 addition & 1 deletion test/_helpers/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const serverSetup = () => {
return server;
};

const next = function next() {};
const next = () => {};
// Seed some example documents as requests to be saved
const seed = async (uttori) => {
const response = { set: () => {}, render: () => {}, redirect: () => {} };
Expand Down
2 changes: 0 additions & 2 deletions test/preview.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck
/* eslint-disable ramda/prefer-ramda-boolean */
const test = require('ava');
const sinon = require('sinon');
const request = require('supertest');
Expand Down
2 changes: 0 additions & 2 deletions test/save.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck
/* eslint-disable ramda/prefer-ramda-boolean */
const test = require('ava');
const request = require('supertest');
const sinon = require('sinon');
Expand Down
17 changes: 9 additions & 8 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare module "config" {
export { UttoriWikiConfig };
}
type UttoriWikiConfig = {
production?: boolean;
site_title?: string;
site_header?: string;
site_footer?: string;
Expand All @@ -18,7 +19,7 @@ declare module "config" {
home_page?: string;
ignore_slugs: string[];
excerpt_length?: number;
site_url: string;
site_url?: string;
theme_dir?: string;
public_dir?: string;
use_delete_key?: boolean;
Expand Down Expand Up @@ -52,7 +53,7 @@ declare module "config" {
historyRestoreRoute?: Function;
notFoundRoute?: Function;
saveValidRoute?: Function;
routeMiddleware: {
routeMiddleware?: {
home: Function[];
tagIndex: Function[];
tag: Function[];
Expand Down Expand Up @@ -85,9 +86,9 @@ declare module "wiki" {
bindRoutes(server: Application): void;
home(request: Request, response: Response, next: Function): Promise<void>;
homepageRedirect(request: Request, response: Response, _next: Function): void;
tagIndex(request: Request, response: Response, _next: Function): Promise<void>;
tagIndex(request: Request, response: Response, next: Function): Promise<void>;
tag(request: Request, response: Response, next: Function): Promise<void>;
search(request: Request, response: Response, _next: Function): Promise<void>;
search(request: Request, response: Response, next: Function): Promise<void>;
edit(request: Request, response: Response, next: Function): Promise<void>;
delete(request: Request, response: Response, next: Function): Promise<void>;
save(request: Request, response: Response, next: Function): Promise<void>;
Expand All @@ -98,8 +99,8 @@ declare module "wiki" {
historyIndex(request: Request, response: Response, next: Function): Promise<void>;
historyDetail(request: Request, response: Response, next: Function): Promise<void>;
historyRestore(request: Request, response: Response, next: Function): Promise<void>;
notFound(request: Request, response: Response, _next: Function): Promise<void>;
saveValid(request: Request, response: Response, _next: Function): Promise<void>;
notFound(request: Request, response: Response, next: Function): Promise<void>;
saveValid(request: Request, response: Response, next: Function): Promise<void>;
getTaggedDocuments(tag: string, limit?: number): Promise<any[]>;
}
namespace UttoriWiki {
Expand All @@ -113,8 +114,8 @@ declare module "wiki" {
excerpt: string;
content: string;
html?: string;
createDate?: number;
updateDate?: number;
createDate: number;
updateDate: number;
tags: string[];
redirects?: string[];
};
Expand Down

0 comments on commit 95e9275

Please sign in to comment.