happypeter / onestep

haoqicat.com 代码
http://haoqicat.com
171 stars 90 forks source link

显示课程详情 #721

Closed happypeter closed 6 years ago

happypeter commented 6 years ago

不考虑视频详情页,主要是视频目录页

happypeter commented 6 years ago

数据还是都放到数据库中把,管理方便。要导出成 gitbook 格式也是非常容易。

happypeter commented 6 years ago

参考:https://github.com/happypeter/onestep/issues/685#issuecomment-355691756

happypeter commented 6 years ago
mongoimport -d newcat -c courses --file CourseIndex.json
happypeter commented 6 years ago

得到 CourseIndex.json 用到的脚本

getIndex/index.js

const fs = require('fs')
const dataArr = require('./data')

const changeSection = section => {
  return section.map(item => {
    return { title: item.title, uid: item.link }
  })
}

const changContent = content => {
  return content.map(t => {
    const section = changeSection(t.section)
    return { ...t, section }
  })
}

const link2uid = obj => {
  const content = changContent(obj.content)
  return { ...obj, content }
}

let arr = []
dataArr.forEach(t => {
  const { uid } = t
  const courseJson = fs.readFileSync(
    `../doc-haoqi/${uid}/doc/index.json`,
    'utf-8'
  )
  const courseObj = JSON.parse(courseJson)
  const newObj = link2uid(courseObj)
  arr.push({ ...newObj, uid })
})

let finalStr = arr.map(item => JSON.stringify(item)).join('\n')

fs.writeFile('CourseIndex.json', finalStr, err => {
  if (err) throw err
  console.log('The file has been restructured!')
})

getIndex/data.js

const dataArr = [
  {
    serialNo: '61',
    title: 'Material UI 自定制',
    uid: 'mui-cat'
  },
  {
    serialNo: '60',
    title: 'React 图片上传',
    uid: 'img-upload'
  },
  {
    serialNo: '59',
    title: 'JWT 破冰',
    uid: 'jwt'
  },
  {
    serialNo: '58',
    title: 'Express 实作 API (第二版)',
    uid: 'express-love-api-v2'
  },
  {
    serialNo: '57',
    title: 'Ajax 摩登之旅',
    uid: 'ajax-tour'
  },
  {
    serialNo: '56',
    title: 'React-static 摩登静态化之路',
    uid: 'react-static-way'
  },
  {
    serialNo: '55',
    title: 'React 社交化电商--架构篇(第二版)',
    uid: 'yummy-v2'
  },
  {
    serialNo: '54',
    title: '函数式编程',
    uid: 'fp'
  },
  {
    serialNo: '53',
    title: 'React 项目测试',
    uid: 'test-react'
  },
  {
    serialNo: '52',
    title: 'Gulp Flexbox 响应式网站(第二版)',
    uid: 'gulp-flex-res-v2'
  },
  {
    serialNo: '51',
    title: 'React 婴儿(第三版)',
    uid: 'react-baby-v3'
  },
  {
    serialNo: '50',
    title: 'JS 面向对象之旅(第二版)',
    uid: 'o-o-js-v2'
  },
  {
    serialNo: '49',
    title: '用 gitbook 做笔记',
    uid: 'gitbook'
  },
  {
    serialNo: '48',
    title: '好奇图书馆',
    uid: 'haoqi-lib'
  },
  {
    serialNo: '47',
    title: 'redux 实现 Todo App',
    uid: 'redux-todo'
  },
  {
    serialNo: '46',
    title: 'VSCode 爱上 JS',
    uid: 'vscode'
  },
  {
    serialNo: '45',
    title: 'Hello Vuex 第二版',
    uid: 'vuex-hello-v2'
  },
  {
    serialNo: '44',
    title: '塔顶上的 redux 第二版',
    uid: 'redux-tower-v2'
  },
  {
    serialNo: '43',
    title: 'Hello Redux 第三版',
    uid: 'redux-hello-v3'
  },
  {
    serialNo: '42',
    title: '用 redux 实现购物车',
    uid: 'redux-cart'
  },
  {
    serialNo: '41',
    title: '定制 Videojs 播放器',
    uid: 'happy-videojs'
  },
  {
    serialNo: '40',
    title: '用 Gatsby 开发 SPA 架构的博客',
    uid: 'gatsby'
  },
  {
    serialNo: '2',
    title: 'Meteor-React 小鸟课程',
    uid: 'meteor-react-bird'
  },
  {
    serialNo: '3',
    title: 'Happypeter 的摩登 JS 王国',
    uid: 'happypeter-js-kingdom'
  },
  {
    serialNo: '4',
    title: 'Webpack-React 鼹鼠',
    uid: 'webpack-react-mole'
  },
  {
    serialNo: '6',
    title: '驾驭命令行怪兽',
    uid: 'ride-cli-monster'
  },
  {
    serialNo: '7',
    title: '跟 Peter 学 HTTP',
    uid: 'http-with-peter'
  },
  {
    serialNo: '8',
    title: 'Flexbox 舞娘',
    uid: 'flexbox-dancer'
  },
  {
    serialNo: '9',
    title: 'Nodejs 乐高',
    uid: 'nodejs-lego'
  },
  {
    serialNo: '10',
    title: '支付宝站内集成',
    uid: 'alipay'
  },
  {
    serialNo: '11',
    title: 'Atom 爱上 JS',
    uid: 'atom-love-js'
  },
  {
    serialNo: '13',
    title: 'Git 北京',
    uid: 'gitbeijing'
  },
  {
    serialNo: '15',
    title: 'Chrome 开发者工具',
    uid: 'chrome-devtools'
  },
  {
    serialNo: '16',
    title: '小白变怪兽',
    uid: 'bianguaishou'
  },
  {
    serialNo: '17',
    title: 'HTML 七日行',
    uid: 'html7'
  },
  {
    serialNo: '21',
    title: 'GraphQL 婴儿',
    uid: 'graphql-baby'
  },
  {
    serialNo: '22',
    title: 'Webpack-React 环境搭建技巧',
    uid: 'webpack-react-tricks'
  },
  {
    serialNo: '23',
    title: '如何制作视频课程?',
    uid: 'making-videos-howto'
  },
  {
    serialNo: '24',
    title: '微信小程序之吻',
    uid: 'weapp'
  },
  {
    serialNo: '25',
    title: 'SVG 甜点',
    uid: 'svghere'
  },
  {
    serialNo: '26',
    title: '认证授权双A之旅',
    uid: 'aa-journey'
  },
  {
    serialNo: '28',
    title: 'React Router 第四版',
    uid: 'react-router-v4'
  },
  {
    serialNo: '30',
    title: '克隆美团外卖',
    uid: 'meituan'
  },
  {
    serialNo: '31',
    title: '快乐新知比特币',
    uid: 'bitcoin'
  },
  {
    serialNo: '37',
    title: '跟 Peter 做腾讯云客户端',
    uid: 'qcloud'
  },
  {
    serialNo: '38',
    title: 'React 社交化电商--功能篇',
    uid: 'yummy-p2'
  },
  {
    serialNo: '39',
    title: '蚂蚁设计实战(第二版)',
    uid: 'antd-v2'
  }
]

module.exports = dataArr
happypeter commented 6 years ago

下载 doc-haoqi 放到和 getIndex/ 平级即可。