diff --git a/README.md b/README.md index 253eb9e..a05a468 100644 --- a/README.md +++ b/README.md @@ -15,15 +15,29 @@ $ npm install Generate: ``` bash -$ hexo generate +$ hexo g ``` Run server: ``` bash -$ hexo server --watch +$ hexo s --watch ``` +## Deployment + +1. Generate and optimize assets + + ```bash + gulp + ``` + +2. Deploy to the gh-pages branch + + ```bash + hexo deploy + ``` + ## Contributors - English - [mamboer] diff --git a/_config.yml b/_config.yml index f9172aa..c53a8e2 100644 --- a/_config.yml +++ b/_config.yml @@ -5,7 +5,7 @@ author: 凹凸实验室(LV&天哥) language: zh-cn timezone: UTC url: http://aotu.io/mac -root: / +root: /mac/ permalink: news/:year/:month/:day/:title/ archive_dir: news code_dir: downloads/code diff --git a/gulpfile.js b/gulpfile.js index 2e9be55..ee1c7f3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,8 +1,13 @@ 'use strict'; -var gulp = require('gulp'); -var $ = require('gulp-load-plugins')(); -var cssnano = require('cssnano'); +var gulp = require('gulp'), + $ = require('gulp-load-plugins')(), + cssnano = require('cssnano'), + yaml = require('js-yaml'), + fs = require('fs'), + cfg = yaml.safeLoad(fs.readFileSync('_config.yml')); + +require('shelljs/global'); var htmlMinifierOptions = { removeComments: true, @@ -17,16 +22,20 @@ var htmlMinifierOptions = { var dirs = { public: 'public', - revSrc: 'public/build', - revDist: 'public/dist', fonts: 'public/fonts', - screenshots: 'public/dist/screenshots' + imgs: 'public/img', + assetsDir:'public/assets' }; -gulp.task('useref', function(){ +gulp.task('useref', ['hexo'], function(){ return gulp.src('public/**/*.html') - .pipe($.useref({searchPath:'public'})) + .pipe($.useref({ + searchPath:'public', + transformPath: function(filePath) { + return filePath.replace(dirs.public + cfg.root, dirs.public + '/'); + } + })) .pipe($.if('*.css', $.postcss([ cssnano() ]))) @@ -36,87 +45,67 @@ gulp.task('useref', function(){ .pipe(gulp.dest('public')); }); -gulp.task('fonts', function(){ - +gulp.task('rev:media', function(){ - return gulp.src([dirs.fonts + '/**/*'], {base: dirs.public}) + return gulp.src([dirs.fonts + '/**/*', dirs.imgs + '/**/*'], {base: dirs.public}) .pipe($.rev()) - .pipe(gulp.dest(dirs.revDist)) - .pipe($.rev.manifest('rev-fonts.json')) - .pipe(gulp.dest(dirs.revDist)); + .pipe(gulp.dest(dirs.assetsDir)) + .pipe($.rev.manifest('rev-media.json')) + .pipe(gulp.dest(dirs.assetsDir)); }); +gulp.task('rev:scripts', ['useref', 'rev:media'], function(){ + var manifest = gulp.src(dirs.assetsDir + '/rev-media.json'); -gulp.task('rev', ['useref', 'fonts'], function(){ - - var basePath = dirs.revSrc, - distPath = dirs.revDist; - - return gulp.src([basePath+'/css/*.css', basePath + '/js/*.js'], {base: basePath}) + return gulp.src([dirs.public + '/css/dist*.css', dirs.public + '/js/dist*.js'], {base: dirs.public}) .pipe($.rev()) - .pipe(gulp.dest(distPath)) + .pipe($.revReplace({ + manifest: manifest + })) + .pipe(gulp.dest(dirs.assetsDir)) .pipe($.rev.manifest()) - .pipe(gulp.dest(distPath)); + .pipe(gulp.dest(dirs.assetsDir)); }); -gulp.task("revreplace", ["rev"], function(){ - - return gulp.src([dirs.public + '/**/rev-manifest.json', "public/**/*.html", "public/dist/**/*.css"]) - .pipe($.revCollector({ - replaceReved:true, - dirReplacements: { - 'build/':'dist/' - } - })) - .pipe($.ignore.exclude('./**/rev-*.json')) - .pipe(gulp.dest(dirs.public)); -}); +gulp.task('img:min', ['rev:media'], function(){ -gulp.task('screenshot:rev', function(){ - return gulp.src('public/themes/screenshots/*.png') - .pipe($.rev()) - .pipe(gulp.dest(dirs.screenshots)) - .pipe($.rev.manifest()) - .pipe(gulp.dest(dirs.screenshots)); + var pngquant = require('imagemin-pngquant'); + + return gulp.src(dirs.assetsDir + '/img/**/*', {base: dirs.assetsDir}) + .pipe($.imagemin({ + progressive: true, + svgoPlugins: [{removeViewBox:false}], + use:[pngquant()] + })) + .pipe(gulp.dest(dirs.assetsDir)) }); -gulp.task('screenshot:resize', ['screenshot:rev'], function(){ - var resizeOptions = { - width: 400, - height: 250, - crop: true - }; - - return gulp.src('public/dist/screenshots/*.png') - // Append "@2x" to the original images - .pipe($.rename({ - suffix: '@2x' - })) - // Copy original images - .pipe(gulp.dest(dirs.screenshots)) - // Resize images - .pipe($.imageResize(resizeOptions)) - // Remove "@2x" in filename - .pipe($.rename(function(path){ - path.basename = path.basename.replace('@2x', ''); - return path; - })) - // Save resized images - .pipe(gulp.dest(dirs.screenshots)); +gulp.task("rev:replace", ["rev:scripts"], function(){ + var manifest = gulp.src([dirs.assetsDir + '/rev-*.json']); + + return gulp.src([ dirs.public + "/**/*.html"]) + .pipe($.revReplace({ + manifest: manifest, + modifyReved:function(fileName){ + if(fileName.indexOf('/dist') > -1){ + //special files proccessed by gulp-useref + fileName = cfg.root + 'assets/' + fileName; + }else { + fileName = 'assets/' + fileName; + } + return fileName; + } + })) + .pipe(gulp.dest(dirs.public)); }); -gulp.task('screenshot:revreplace', ['screenshot:rev'], function(){ - return gulp.src([dirs.screenshots + '/rev-manifest.json', 'public/themes/index.html']) - .pipe($.revCollector({ - replaceReved: true, - dirReplacements: { - '/themes/screenshots': '/dist/screenshots' - } - })) - .pipe(gulp.dest('public/themes')); +gulp.task('hexo', function(){ + + exec('hexo g'); + }); -gulp.task('screenshot', ['screenshot:rev', 'screenshot:resize', 'screenshot:revreplace']); -gulp.task('default', ['revreplace', 'screenshot']); +gulp.task('img', ['img:min']); +gulp.task('default', ['rev:replace', 'img']); diff --git a/package.json b/package.json index 93ccecf..83d73fd 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "gulp-if": "^2.0.0", "gulp-ignore": "^2.0.1", "gulp-image-resize": "^0.7.1", + "gulp-imagemin": "^2.4.0", "gulp-load-plugins": "^1.1.0", "gulp-minify-css": "^1.2.1", "gulp-minify-html": "^1.0.4", @@ -38,7 +39,10 @@ "gulp-rev-collector": "^1.0.2", "gulp-rev-replace": "^0.4.2", "gulp-uglify": "^1.5.1", - "gulp-useref": "^3.0.0" + "gulp-useref": "^3.0.0", + "imagemin-pngquant": "^4.2.0", + "js-yaml": "^3.4.3", + "shelljs": "^0.5.3" }, "optionalDependencies": { "hexo-browsersync": "^0.1.0" diff --git a/scripts/helpers.js b/scripts/helpers.js index b1f6c97..25b1a6f 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -76,7 +76,7 @@ hexo.extend.helper.register('header_menu', function(className){ var isDefaultLang = lang === 'zh-cn'; _.each(menu, function(path, title){ - if (!isDefaultLang && ~localizedPath.indexOf(title)) path = lang + path; + if (!isDefaultLang && ~localizedPath.indexOf(title)) path = lang + '/' + path; result += '
  • '; result += '' + self.__('menu.' + title) + ''; @@ -95,9 +95,12 @@ hexo.extend.helper.register('canonical_url', function(lang){ hexo.extend.helper.register('url_for_lang', function(path){ var lang = this.page.lang; - var url = this.url_for(path); + var isDefaultLang = lang === 'zh-cn'; + var url = path; + + if (!isDefaultLang && lang) url = lang + '/' + url; - if (lang !== 'zh-cn' && url[0] === '/') url = '/' + lang + url; + url = this.url_for(url); return url; }); diff --git a/source/_data/menu.yml b/source/_data/menu.yml index 11dffbc..609d3c5 100644 --- a/source/_data/menu.yml +++ b/source/_data/menu.yml @@ -1,2 +1,2 @@ -docs: /docs/ -news: /news/ +docs: docs/ +news: news/ diff --git a/source/_posts/2015-11-13-first-released.md b/source/_posts/2015-11-13-first-released.md index 1dea0a0..2eec021 100644 --- a/source/_posts/2015-11-13-first-released.md +++ b/source/_posts/2015-11-13-first-released.md @@ -1,8 +1,8 @@ -title: MAC全栈开发环境搭建指南 - 预览版 +title: V1.0.0 Preview (预览版) layout: post --- -`全栈MAC装机指南` 中文预览版发布。感谢各位开源贡献人员。 +`MAC全栈开发环境搭建指南` 中文预览版发布。感谢各位开源贡献人员。 ## 特性 diff --git a/source/_posts/2015-11-15-beta-released.md b/source/_posts/2015-11-15-beta-released.md new file mode 100644 index 0000000..c558443 --- /dev/null +++ b/source/_posts/2015-11-15-beta-released.md @@ -0,0 +1,15 @@ +title: V1.0.0 Beta Released +layout: post +--- + +`MAC全栈开发环境搭建指南` 中英双语V1.0.0 Beta版本发布。感谢各位开源贡献人员。 + +## 特性 + +- 中文双语版本 + + 英文为简版,6级刚刚及格抱歉了~ + 欢迎英文达人参与 `MAC全栈开发环境搭建指南` 的维护。 + +- 修复了配置站点根目录为网站子目录时切换语言404的bug。 +- 去掉了retinajs的特性,现在srcset支持不错,没必要使用retinajs做响应式图片加载。 diff --git a/source/docs/dev-common/vim.md b/source/docs/dev-common/vim.md index a5982dc..77184ec 100644 --- a/source/docs/dev-common/vim.md +++ b/source/docs/dev-common/vim.md @@ -72,4 +72,4 @@ set autoread 看不清楚可以新窗口打开! -![Vim Cheatsheet](../img/vim.png) +![Vim Cheatsheet](../../img/vim.png) diff --git a/source/docs/dev-fd/sublime-text.md b/source/docs/dev-fd/sublime-text.md index 427d9d2..1ae64bb 100644 --- a/source/docs/dev-fd/sublime-text.md +++ b/source/docs/dev-fd/sublime-text.md @@ -73,7 +73,7 @@ SublimeText所有插件都依赖于`Package Control`,默认情况下`Package C 预览效果: -![material theme](../img/material-theme.png) +![material theme](../../img/material-theme.png) ## 推荐插件 diff --git a/source/docs/dev-ios/crash-logs.md b/source/docs/dev-ios/crash-logs.md index 668f2e6..d1d9ad4 100644 --- a/source/docs/dev-ios/crash-logs.md +++ b/source/docs/dev-ios/crash-logs.md @@ -4,7 +4,7 @@ title: 查看IOS应用崩溃时的日志 首先用iTunes的同步功能,将手机的各种信息同步至电脑: -![iTunes Sync](../img/crash-logs.jpg) +![iTunes Sync](../../img/crash-logs.jpg) 然后,崩溃日志可以在这里找到: diff --git a/source/en/docs/common.md b/source/en/docs/common.md index da0e3f7..c3f6eb5 100644 --- a/source/en/docs/common.md +++ b/source/en/docs/common.md @@ -23,14 +23,14 @@ Your network DNS is located at `System Preferences > Network > Wi-Fi > Advanced We recommend the default Mail Client distributed along with MAC OS. -### Office & Writing +### Office and Writing 1. [Office](http://soft.macx.cn/soft4350.htm) 2. [Evernote](https://www.evernote.com/) 3. [OneNote](https://onenote.com) 4. [Marxi.co](https://marxi.co/) -### Achive & Unachive +### Achive and Unachive 1. The Unachiver diff --git a/source/en/docs/contributing.md b/source/en/docs/contributing.md index 29b2769..e2c7bd1 100644 --- a/source/en/docs/contributing.md +++ b/source/en/docs/contributing.md @@ -13,7 +13,7 @@ The document site was powered by [hexo](https://hexo.io), so install hexo locall npm i -g hexo-cli ``` -### How to contribute? +### How to contribute 1. Fork [o2team/mac]. 2. Clone the forked repo and install the dependencies diff --git a/source/en/docs/dev-common/vim.md b/source/en/docs/dev-common/vim.md index 17669e7..98909b6 100644 --- a/source/en/docs/dev-common/vim.md +++ b/source/en/docs/dev-common/vim.md @@ -61,4 +61,4 @@ sh ~/.vim_runtime/install_awesome_vimrc.sh ### Vim Cheatsheet -![Vim Cheatsheet](../../../docs/img/vim.png) +![Vim Cheatsheet](../../../img/vim.png) diff --git a/source/en/docs/dev-fd/sublime-text.md b/source/en/docs/dev-fd/sublime-text.md index a0c4dd5..cf5860a 100644 --- a/source/en/docs/dev-fd/sublime-text.md +++ b/source/en/docs/dev-fd/sublime-text.md @@ -72,7 +72,7 @@ We recommended the cool dark [Material Theme](https://github.com/equinusocio/mat Preview: -![material theme](../img/material-theme.png) +![material theme](../../../img/material-theme.png) ## Recommened Plugins diff --git a/source/en/docs/dev-ios/crash-logs.md b/source/en/docs/dev-ios/crash-logs.md index 10190be..b7f185d 100644 --- a/source/en/docs/dev-ios/crash-logs.md +++ b/source/en/docs/dev-ios/crash-logs.md @@ -4,7 +4,7 @@ title: Crashing Logs Firstly, backup the phone via iTunes -![iTunes Sync](../../../docs/img/crash-logs.jpg) +![iTunes Sync](../../../img/crash-logs.jpg) Then,you can find the Crashing Logs at: diff --git a/source/docs/img/crash-logs.jpg b/source/img/crash-logs.jpg similarity index 100% rename from source/docs/img/crash-logs.jpg rename to source/img/crash-logs.jpg diff --git a/source/docs/img/material-theme.png b/source/img/material-theme.png similarity index 100% rename from source/docs/img/material-theme.png rename to source/img/material-theme.png diff --git a/source/themes/screenshots/Foundation.png b/source/img/themes/Foundation.png similarity index 100% rename from source/themes/screenshots/Foundation.png rename to source/img/themes/Foundation.png diff --git a/source/themes/screenshots/Freemind.png b/source/img/themes/Freemind.png similarity index 100% rename from source/themes/screenshots/Freemind.png rename to source/img/themes/Freemind.png diff --git a/source/themes/screenshots/Hueman.png b/source/img/themes/Hueman.png similarity index 100% rename from source/themes/screenshots/Hueman.png rename to source/img/themes/Hueman.png diff --git a/source/themes/screenshots/Icarus.png b/source/img/themes/Icarus.png similarity index 100% rename from source/themes/screenshots/Icarus.png rename to source/img/themes/Icarus.png diff --git a/source/themes/screenshots/Jacman.png b/source/img/themes/Jacman.png similarity index 100% rename from source/themes/screenshots/Jacman.png rename to source/img/themes/Jacman.png diff --git a/source/themes/screenshots/Jekyll.png b/source/img/themes/Jekyll.png similarity index 100% rename from source/themes/screenshots/Jekyll.png rename to source/img/themes/Jekyll.png diff --git a/source/themes/screenshots/Maupassant.png b/source/img/themes/Maupassant.png similarity index 100% rename from source/themes/screenshots/Maupassant.png rename to source/img/themes/Maupassant.png diff --git a/source/themes/screenshots/Minos.png b/source/img/themes/Minos.png similarity index 100% rename from source/themes/screenshots/Minos.png rename to source/img/themes/Minos.png diff --git a/source/themes/screenshots/NexT.png b/source/img/themes/NexT.png similarity index 100% rename from source/themes/screenshots/NexT.png rename to source/img/themes/NexT.png diff --git a/source/themes/screenshots/Simplest.png b/source/img/themes/Simplest.png similarity index 100% rename from source/themes/screenshots/Simplest.png rename to source/img/themes/Simplest.png diff --git a/source/themes/screenshots/Tranquilpeak.png b/source/img/themes/Tranquilpeak.png similarity index 100% rename from source/themes/screenshots/Tranquilpeak.png rename to source/img/themes/Tranquilpeak.png diff --git a/source/themes/screenshots/Wixo.png b/source/img/themes/Wixo.png similarity index 100% rename from source/themes/screenshots/Wixo.png rename to source/img/themes/Wixo.png diff --git a/source/themes/screenshots/Yelee.png b/source/img/themes/Yelee.png similarity index 100% rename from source/themes/screenshots/Yelee.png rename to source/img/themes/Yelee.png diff --git a/source/themes/screenshots/carbon.png b/source/img/themes/carbon.png similarity index 100% rename from source/themes/screenshots/carbon.png rename to source/img/themes/carbon.png diff --git a/source/themes/screenshots/hexadillax.png b/source/img/themes/hexadillax.png similarity index 100% rename from source/themes/screenshots/hexadillax.png rename to source/img/themes/hexadillax.png diff --git a/source/themes/screenshots/hexoThemeKacper.png b/source/img/themes/hexoThemeKacper.png similarity index 100% rename from source/themes/screenshots/hexoThemeKacper.png rename to source/img/themes/hexoThemeKacper.png diff --git a/source/themes/screenshots/landscape.png b/source/img/themes/landscape.png similarity index 100% rename from source/themes/screenshots/landscape.png rename to source/img/themes/landscape.png diff --git a/source/themes/screenshots/light.png b/source/img/themes/light.png similarity index 100% rename from source/themes/screenshots/light.png rename to source/img/themes/light.png diff --git a/source/themes/screenshots/phase.png b/source/img/themes/phase.png similarity index 100% rename from source/themes/screenshots/phase.png rename to source/img/themes/phase.png diff --git a/source/themes/screenshots/simpleblock.png b/source/img/themes/simpleblock.png similarity index 100% rename from source/themes/screenshots/simpleblock.png rename to source/img/themes/simpleblock.png diff --git a/source/themes/screenshots/ttstyle.png b/source/img/themes/ttstyle.png similarity index 100% rename from source/themes/screenshots/ttstyle.png rename to source/img/themes/ttstyle.png diff --git a/source/themes/screenshots/yinwang.png b/source/img/themes/yinwang.png similarity index 100% rename from source/themes/screenshots/yinwang.png rename to source/img/themes/yinwang.png diff --git a/source/themes/screenshots/zzoman2015.png b/source/img/themes/zzoman2015.png similarity index 100% rename from source/themes/screenshots/zzoman2015.png rename to source/img/themes/zzoman2015.png diff --git a/source/docs/img/vim.png b/source/img/vim.png similarity index 100% rename from source/docs/img/vim.png rename to source/img/vim.png diff --git a/themes/navy/layout/layout.swig b/themes/navy/layout/layout.swig index c654dbd..2014948 100644 --- a/themes/navy/layout/layout.swig +++ b/themes/navy/layout/layout.swig @@ -2,6 +2,7 @@ {{ partial('partial/head') }} +
    {{ partial('partial/header') }} {{ body }} @@ -10,5 +11,6 @@
    {{ partial('partial/mobile_nav') }} {{ partial('partial/after_footer') }} +
    diff --git a/themes/navy/layout/partial/after_footer.swig b/themes/navy/layout/partial/after_footer.swig index 95536c1..ee78ca3 100644 --- a/themes/navy/layout/partial/after_footer.swig +++ b/themes/navy/layout/partial/after_footer.swig @@ -1,14 +1,14 @@ - -{{ js('js/jquery-2.1.4.min') }} -{{ js('js/retina') }} + +{{ js('js/jquery') }} +{{ js('js/hammer') }} {{ js('assets/bootstrap/js/bootstrap') }} {{ js('js/lang_select') }} {{ js('js/toc') }} {{ js('js/mobile_nav') }} {% if page.layout === 'plugins' %} - + {{ js('js/lunr') }} {{ js('js/plugins') }} diff --git a/themes/navy/layout/partial/head.swig b/themes/navy/layout/partial/head.swig index 9d093ec..07c7843 100644 --- a/themes/navy/layout/partial/head.swig +++ b/themes/navy/layout/partial/head.swig @@ -8,27 +8,27 @@ {% if page.layout == 'page' or page.layout == 'index' %} {% for lang in site.data.languages %} - + {% endfor %} {% endif %} - - - - - - - - - - - - - + + + + + + + + + + + + + - + - + {{ css('css/navy') }} @@ -42,4 +42,9 @@ {{ partial('baidu_analytics') }} + diff --git a/themes/navy/layout/partial/header.swig b/themes/navy/layout/partial/header.swig index ea93679..cd01d36 100644 --- a/themes/navy/layout/partial/header.swig +++ b/themes/navy/layout/partial/header.swig @@ -1,7 +1,7 @@