diff --git a/mock/categories.js b/mock/categories.js new file mode 100755 index 0000000..222cfd4 --- /dev/null +++ b/mock/categories.js @@ -0,0 +1,28 @@ +const faker = require("faker"); +const _ = require("lodash"); +const constants = require("./constants"); + +function genCategories( + level = 0, + depth = 3, + breadth = 20 +) { + if (level < depth) { + return _.range(_.random(breadth)).map(() => ({ + createdBy: faker.random.uuid(), + createdAt: faker.date.recent(), + updatedAt: faker.date.recent(), + id: faker.random.uuid(), + cover: faker.image.imageUrl(), + title: faker.lorem.words(), + summary: faker.lorem.paragraph(), + weight: faker.random.number(20), + ns: constants.NAMESPACE, + children: genCategories(level + 1, depth, breadth), + })); + } + + return []; +} + +module.exports = genCategories(); diff --git a/mock/comments.js b/mock/comments.js new file mode 100755 index 0000000..c830507 --- /dev/null +++ b/mock/comments.js @@ -0,0 +1,19 @@ +const faker = require("faker"); +const _ = require("lodash"); +const constants = require("./constants"); +const posts = require("./posts"); + +module.exports = _.range(500).map(() => ({ + id: faker.random.uuid(), + createdBy: faker.random.uuid(), + author: { + id: faker.random.uuid(), + name: faker.name.findName(), + }, + content: faker.lorem.paragraph(), + format: faker.random.arrayElement(["TEXT", "HTML", "MARKDOWN"]), + type: "COMMENT", + post: faker.random.arrayElement(posts).id, + replies: [], + ns: constants.NAMESPACE, +})); diff --git a/mock/constants.js b/mock/constants.js new file mode 100755 index 0000000..d2303d0 --- /dev/null +++ b/mock/constants.js @@ -0,0 +1 @@ +exports.NAMESPACE = "/navinfo"; diff --git a/mock/index.js b/mock/index.js old mode 100644 new mode 100755 index 2b42735..5c83e65 --- a/mock/index.js +++ b/mock/index.js @@ -1,30 +1,26 @@ -const faker = require("faker"); -const _ = require("lodash"); - -const pets = count => - _.range(count).map((val, index) => ({ - id: faker.random.uuid(), - name: faker.name.lastName(), - tag: faker.random.arrayElement(["CAT", "DOG", "RABBIT"]), - })); +const posts = require("./posts"); +const comments = require("./comments"); +const categories = require("./categories"); +const tags = require("./tags"); module.exports = { /** * mock data */ db: { - pets, + posts, + categories, + comments, + tags, }, /** - * rewrite + * rewrites */ - rewrite: {}, + rewrites: {}, /** - * Config mock server + * routers */ - serverOpts: { - delay: 500, - }, + routers: [], }; diff --git a/mock/posts.js b/mock/posts.js new file mode 100755 index 0000000..dbc6526 --- /dev/null +++ b/mock/posts.js @@ -0,0 +1,41 @@ +const faker = require("faker"); +const _ = require("lodash"); +const constants = require("./constants"); + +const categories = require("./categories"); +const tags = require("./tags"); + +module.exports = _.range(categories.length * 5).map((x, index) => { + const published = faker.random.boolean(); + return { + id: faker.random.uuid(), + createdBy: faker.random.uuid(), + createdAt: faker.date.recent(), + author: { + id: faker.random.uuid(), + name: faker.name.findName(), + }, + uri: "", + category: faker.random.arrayElement(categories).id, + content: `
${faker.lorem.paragraphs().replace(/\n/g, "
")}`, + format: faker.random.arrayElement(["TEXT", "HTML"]), + cover: faker.image.imageUrl(), + photos: [faker.image.imageUrl()], + pinned: faker.random.boolean(), + published, + publishedAt: published ? faker.date.recent() : null, + source: null, + summary: faker.lorem.paragraph, + tags: tags.slice(Math.floor(Math.random()*tags.length)).map(item => item.name), + title: faker.lorem.words(), + topics: null, + weight: faker.random.number, + likes: 0, + favs: 0, + ns: constants.NAMESPACE, + type: "ARTICLE", + lang: faker.random.arrayElement(["zh", "en"]), + link: faker.internet.url, + date: faker.date.recent(), + }; +}); diff --git a/mock/tags.js b/mock/tags.js new file mode 100755 index 0000000..1e8cd73 --- /dev/null +++ b/mock/tags.js @@ -0,0 +1,7 @@ +const faker = require("faker"); +const _ = require("lodash"); + +module.exports = _.range(20).map(() => ({ + name: faker.random.word(), + count: faker.random.number(100), +}));