1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-07-30 02:29:42 +02:00

Editorjs checklist tool (#98)

Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
This commit is contained in:
Alexander Menshikov 2020-05-09 05:38:25 +03:00 committed by GitHub
parent c0a4f6f3fd
commit b744ed592a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 2628 additions and 2152 deletions

View file

@ -2,7 +2,7 @@ const { aliases: aliasesDb } = require('../utils/database/index');
const { binaryMD5 } = require('../utils/crypto');
/**
* @typedef {Object} AliasData
* @typedef {object} AliasData
* @property {string} _id - alias id
* @property {string} hash - alias binary hash
* @property {string} type - entity type
@ -25,22 +25,26 @@ class Alias {
/**
* Return Alias types
*
* @returns {Object}
* @returns {object}
*/
static get types() {
return {
PAGE: 'page'
PAGE: 'page',
};
};
/**
* Find and return alias with given alias
*
* @param {string} aliasName - alias of entity
* @returns {Promise<Alias>}
*/
static async get(aliasName) {
const hash = binaryMD5(aliasName);
let data = await aliasesDb.findOne({ hash: hash, deprecated: false });
let data = await aliasesDb.findOne({
hash: hash,
deprecated: false,
});
if (!data) {
data = await aliasesDb.findOne({ hash: hash });
@ -50,7 +54,7 @@ class Alias {
}
/**
* @constructor
* @class
*
* @param {AliasData} data
* @param {string} aliasName - alias of entity
@ -110,12 +114,13 @@ class Alias {
id: this.id,
type: this.type,
hash: this.hash,
deprecated: this.deprecated
deprecated: this.deprecated,
};
}
/**
* Mark alias as deprecated
*
* @param {string} aliasName - alias of entity
* @returns {Promise<Alias>}
*/

View file

@ -1,7 +1,7 @@
const { files: filesDb } = require('../utils/database/index');
/**
* @typedef {Object} FileData
* @typedef {object} FileData
*
* @property {string} _id - file id
* @property {string} name - original file name
@ -25,6 +25,7 @@ const { files: filesDb } = require('../utils/database/index');
class File {
/**
* Find and return model of file with given id
*
* @param {string} _id - file id
* @returns {Promise<File>}
*/
@ -36,6 +37,7 @@ class File {
/**
* Find and return model of file with given id
*
* @param {string} filename - uploaded filename
* @returns {Promise<File>}
*/
@ -48,7 +50,7 @@ class File {
/**
* Find all files which match passed query object
*
* @param {Object} query
* @param {object} query
* @returns {Promise<File[]>}
*/
static async getAll(query = {}) {
@ -58,7 +60,7 @@ class File {
}
/**
* @constructor
* @class
*
* @param {FileData} data
*/
@ -101,7 +103,7 @@ class File {
filename: this.filename,
path: this.path,
mimetype: this.mimetype,
size: this.size
size: this.size,
};
}
@ -137,8 +139,9 @@ class File {
/**
* Removes unnecessary public folder prefix
*
* @param {string} path
* @return {string}
* @returns {string}
*/
processPath(path) {
return path.replace(/^public/, '');

View file

@ -2,7 +2,7 @@ const urlify = require('../utils/urlify');
const { pages: pagesDb } = require('../utils/database/index');
/**
* @typedef {Object} PageData
* @typedef {object} PageData
* @property {string} _id - page id
* @property {string} title - page title
* @property {string} uri - page uri
@ -23,6 +23,7 @@ const { pages: pagesDb } = require('../utils/database/index');
class Page {
/**
* Find and return model of page with given id
*
* @param {string} _id - page id
* @returns {Promise<Page>}
*/
@ -34,6 +35,7 @@ class Page {
/**
* Find and return model of page with given uri
*
* @param {string} uri - page uri
* @returns {Promise<Page>}
*/
@ -46,7 +48,7 @@ class Page {
/**
* Find all pages which match passed query object
*
* @param {Object} query
* @param {object} query
* @returns {Promise<Page[]>}
*/
static async getAll(query = {}) {
@ -56,7 +58,7 @@ class Page {
}
/**
* @constructor
* @class
*
* @param {PageData} data
*/
@ -89,7 +91,7 @@ class Page {
/**
* Return PageData object
*
* @return {PageData}
* @returns {PageData}
*/
get data() {
return {
@ -97,13 +99,14 @@ class Page {
title: this.title,
uri: this.uri,
body: this.body,
parent: this._parent
parent: this._parent,
};
}
/**
* Extract first header from editor data
* @return {string}
*
* @returns {string}
*/
extractTitleFromBody() {
const headerBlock = this.body ? this.body.blocks.find(block => block.type === 'header') : '';
@ -113,7 +116,8 @@ class Page {
/**
* Transform title for uri
* @return {string}
*
* @returns {string}
*/
transformTitleToUri() {
return urlify(this.title);
@ -184,6 +188,7 @@ class Page {
* Find and return available uri
*
* @returns {Promise<string>}
* @param uri
*/
async composeUri(uri) {
let pageWithSameUriCount = 0;

View file

@ -1,7 +1,7 @@
const { pagesOrder: db } = require('../utils/database/index');
/**
* @typedef {Object} PageOrderData
* @typedef {object} PageOrderData
* @property {string} _id - row unique id
* @property {string} page - page id
* @property {Array<string>} order - list of ordered pages
@ -37,7 +37,7 @@ class PageOrder {
/**
* Find all pages which match passed query object
*
* @param {Object} query
* @param {object} query
* @returns {Promise<Page[]>}
*/
static async getAll(query = {}) {
@ -47,7 +47,7 @@ class PageOrder {
}
/**
* @constructor
* @class
*
* @param {PageOrderData} data
*/
@ -65,6 +65,7 @@ class PageOrder {
/**
* constructor data setter
*
* @param {PageOrderData} pageOrderData
*/
set data(pageOrderData) {
@ -74,13 +75,14 @@ class PageOrder {
/**
* Return Page Children order
*
* @returns {PageOrderData}
*/
get data() {
return {
_id: this._id,
page: '' + this._page,
order: this._order
order: this._order,
};
}
@ -176,7 +178,7 @@ class PageOrder {
/**
* Returns ordered list
*
* @return {string[]}
* @returns {string[]}
*/
get order() {
return this._order;

View file

@ -24,9 +24,9 @@ class User {
}
/**
* @constructor
* @class
*
* @param {Object} userData
* @param {object} userData
*/
constructor(userData) {
this.passHash = userData.passHash;