Git Product home page Git Product logo

blog's Introduction

Blog

博客站点源码

开始对于构建工具的思考

使用webpack,这也是自己较为熟悉的打包工具,能够将多文件打包、代码压缩,更方便的是模块开发。也有缺点,只会监听.js文件,对于其他文件如果没有放在loader中则不会热更新。

使用gulp,基于流的打包工具,目前只知道它能够运行一个个任务,然后构代码,需要手动监听,关键现在社区基本都转webpack了...

遇到的问题:

  1. 原生.html构建,没法儿刷新
  2. 文章id包含在路径中,如xxxid.html,这需要nginx转发做处理。webpack构建的dev-server显然没必要

第一个问题的折中解决:html-webpack-plugin提供模板生产,会用到loader加载,这样一来修改之后就能刷新了。也可以不用模板,直接html-loader能够返回字符串生成.html

由于不是生成单个.html文件,故不考虑这样(不太合语义)。设为articles/detail?id=xxx形式,使用query而不是用hash,因为hash会被认为同一个地址,不同文章应该有各自的地址,虽然返回同一个文件且由js加载文章数据。SEO的事之后再考虑

目录结构

├── node_modules          模块目录
├── src                   博客总目录
│   ├── assets            图片、视频等资源文件
│   ├── common            公共样式、js以及一些插件
│   ├── components        通用组件,诸如header等;icon_svg则是图标
│   ├── page.xxx          单个xxx页面,会生成xxx.html
│   │   ├── index.pug     html模版
│   │   ├── index.less    样式
│   │   └── index.js
│   ├── pages.xxx         二级目录,生成一个xxx目录
│   │   └── xxx           与上面page.xxx类似
│   └── layout.pug        博客总布局
├── pages.static          静态页面,内联css与js
│   ├── xxx               生成xxx.html静态页面
│   │   ├── index.js
│   │   └── index.pug
│   └── webpack.config.js 静态页专门的配置
├── webpack               细分配置文件
│   ├── index.js          基本
│   ├── loaders.js        一系列loader
│   └── pages.js          一系列entry以及插件(生成html文件)
├── .eslintrc             eslint配置
├── .gitignore            git忽略配置
├── favicon.ico           网站图标
├── package.json          模块配置
├── README.md             此说明文件
├── webpack.config.dev.js 开发配置
└── webpack.config.js     生产环境配置

部分 SEO 方案

使用 .pug 做为引擎时,打包出来的为静态 .html 文件。完全写死内容不可取,真正的 SSR 需要服务端支持。两难...

其实 pug 在编译时可以传入一些变量、数据,现在开发也是写死了数据调试。一开始的想法是在 .pug 中请求数据,但貌似编译过程是同步的,无法异步加载!

在启动 webpack 打包前,提前准备好数据是个选择。写个脚本跑 node 把数据写到 .json 文件中,pug-loader 里注入即可。

勤打包

😂 每次新增内容,首页并非是最新的,但好歹首页不至于空白。

Pug 打包问题

采用 pug-loader 导致的引用问题:不支持 webpack alias。参考这个 issue。解决办法写在了 issue 中,修改 node_modules/pug-loader/index.js 源码。

Docker 环境

  1. 创建 dockerdata 目录以及必须的几个配置文件
  2. 复制 ssl 本地证书到 dist 目录里
  3. 创建 dist 目录软链接(windows 下 mklink;linux 是 ln)
    • mklink /J dist\admin ..\blog-admin\dist
    • mklink /J dist\api ..\blog-api

blog's People

Contributors

litilexuezha avatar

Watchers

James Cloos avatar

blog's Issues

Tools 工具页添加 source map 解析工具

浏览器里直接解析 source map。本地选择 .js.map 文件,输入报错代码位置,显示源文件名、代码位置、源代码内容。

期望的功能与使用

  1. 选择文件
  2. 输入报错代码位置
  3. 可选显示内容多少

实现思路:读取完本地文件后再加载解析、内容显示库。

[Feature] 添加 ImgViewer 插件

页面上的部分图片,原尺寸被缩小了,导致字太小看不清或者模糊(也可能是压缩导致的)。。。

添加一个 ImgViewer 插件,使得页面上(或某个容器中)的图片可被点击,全屏按原始尺寸浏览。

期望的功能和使用

  1. 网页全屏浏览,显示图片原始尺寸
  2. 左右切换上下一张
  3. 新窗口打开、关闭、全屏
  4. 信息展示:当前第几张 / 总数量、title、尺寸大小?
  5. 缩略图(算了)
ImgViewer.init(selectors); // 默认为 document.body

// TODO: 更多的自定义配置项

提示栏 Alert 抽离成插件

文章详情页的导航栏下错误提示栏,无网络情况下会显示 2 条。

以前仅抽离了公共样式 .tc-error,还需要手写 dom,异常情况还可能出现多条,因此插件化更统一且方便点。

期望的功能及使用

调用 Alert.info('message'),在导航栏下出现提示栏。多次调用也只会出现一条,带关闭按钮。

还应该支持 html。比如

Alert.info('message <a>link</a>');
不同的颜色功用
  • info 正常提示
  • error 错误红色提示
  • warn 警告黄色提示
  • success 成功绿色提示

正常就前两种,定义配色方案,后面有多了再添加方便点。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.