Save title emoji against document
This commit is contained in:
29
package.json
29
package.json
@ -22,19 +22,35 @@
|
|||||||
"precommit": "lint-staged"
|
"precommit": "lint-staged"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*.js": ["eslint --fix", "git add"]
|
"*.js": [
|
||||||
|
"eslint --fix",
|
||||||
|
"git add"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"verbose": false,
|
"verbose": false,
|
||||||
"roots": ["frontend"],
|
"roots": [
|
||||||
|
"frontend"
|
||||||
|
],
|
||||||
"moduleNameMapper": {
|
"moduleNameMapper": {
|
||||||
"^.*[.](s?css|css)$": "<rootDir>/__mocks__/styleMock.js",
|
"^.*[.](s?css|css)$": "<rootDir>/__mocks__/styleMock.js",
|
||||||
"^.*[.](gif|ttf|eot|svg)$": "<rootDir>/__test__/fileMock.js"
|
"^.*[.](gif|ttf|eot|svg)$": "<rootDir>/__test__/fileMock.js"
|
||||||
},
|
},
|
||||||
"moduleFileExtensions": ["js", "jsx", "json"],
|
"moduleFileExtensions": [
|
||||||
"moduleDirectories": ["node_modules"],
|
"js",
|
||||||
"modulePaths": ["frontend"],
|
"jsx",
|
||||||
"setupFiles": ["<rootDir>/setupJest.js", "<rootDir>/__mocks__/window.js"]
|
"json"
|
||||||
|
],
|
||||||
|
"moduleDirectories": [
|
||||||
|
"node_modules"
|
||||||
|
],
|
||||||
|
"modulePaths": [
|
||||||
|
"frontend"
|
||||||
|
],
|
||||||
|
"setupFiles": [
|
||||||
|
"<rootDir>/setupJest.js",
|
||||||
|
"<rootDir>/__mocks__/window.js"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 7.6"
|
"node": ">= 7.6"
|
||||||
@ -69,6 +85,7 @@
|
|||||||
"debug": "2.2.0",
|
"debug": "2.2.0",
|
||||||
"dotenv": "^4.0.0",
|
"dotenv": "^4.0.0",
|
||||||
"emoji-name-map": "1.1.2",
|
"emoji-name-map": "1.1.2",
|
||||||
|
"emoji-regex": "^6.5.1",
|
||||||
"eslint": "^3.19.0",
|
"eslint": "^3.19.0",
|
||||||
"eslint-config-react-app": "^0.6.2",
|
"eslint-config-react-app": "^0.6.2",
|
||||||
"eslint-import-resolver-webpack": "^0.3.1",
|
"eslint-import-resolver-webpack": "^0.3.1",
|
||||||
|
12
server/migrations/20170729215619-emoji.js
Normal file
12
server/migrations/20170729215619-emoji.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
module.exports = {
|
||||||
|
up: (queryInterface, Sequelize) => {
|
||||||
|
queryInterface.addColumn('documents', 'emoji', {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
allowNull: true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
down: (queryInterface, _Sequelize) => {
|
||||||
|
queryInterface.removeColumn('documents', 'emoji');
|
||||||
|
},
|
||||||
|
};
|
@ -2,6 +2,7 @@
|
|||||||
import slug from 'slug';
|
import slug from 'slug';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import randomstring from 'randomstring';
|
import randomstring from 'randomstring';
|
||||||
|
import emojiRegex from 'emoji-regex';
|
||||||
|
|
||||||
import isUUID from 'validator/lib/isUUID';
|
import isUUID from 'validator/lib/isUUID';
|
||||||
import { DataTypes, sequelize } from '../sequelize';
|
import { DataTypes, sequelize } from '../sequelize';
|
||||||
@ -34,6 +35,14 @@ const createUrlId = doc => {
|
|||||||
return (doc.urlId = doc.urlId || randomstring.generate(10));
|
return (doc.urlId = doc.urlId || randomstring.generate(10));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const extractEmoji = doc => {
|
||||||
|
const regex = emojiRegex();
|
||||||
|
const match = regex.exec(doc.title);
|
||||||
|
|
||||||
|
if (match.length) return match[0];
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
const beforeSave = async doc => {
|
const beforeSave = async doc => {
|
||||||
doc.html = convertToMarkdown(doc.text);
|
doc.html = convertToMarkdown(doc.text);
|
||||||
doc.preview = truncateMarkdown(doc.text, 160);
|
doc.preview = truncateMarkdown(doc.text, 160);
|
||||||
@ -53,6 +62,7 @@ const beforeSave = async doc => {
|
|||||||
// We'll add the current user as revision hasn't been generated yet
|
// We'll add the current user as revision hasn't been generated yet
|
||||||
ids.push(doc.lastModifiedById);
|
ids.push(doc.lastModifiedById);
|
||||||
doc.collaboratorIds = _.uniq(ids);
|
doc.collaboratorIds = _.uniq(ids);
|
||||||
|
doc.emoji = extractEmoji(doc);
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
};
|
};
|
||||||
|
@ -22,6 +22,7 @@ async function present(ctx: Object, document: Document, options: ?Options) {
|
|||||||
text: document.text,
|
text: document.text,
|
||||||
html: document.html,
|
html: document.html,
|
||||||
preview: document.preview,
|
preview: document.preview,
|
||||||
|
emoji: document.emoji,
|
||||||
createdAt: document.createdAt,
|
createdAt: document.createdAt,
|
||||||
createdBy: presentUser(ctx, document.createdBy),
|
createdBy: presentUser(ctx, document.createdBy),
|
||||||
updatedAt: document.updatedAt,
|
updatedAt: document.updatedAt,
|
||||||
|
Reference in New Issue
Block a user