diff --git a/source/_data/menu.yml b/source/_data/menu.yml index 314c7d2091..71ff8d9237 100644 --- a/source/_data/menu.yml +++ b/source/_data/menu.yml @@ -1,5 +1,5 @@ docs: /docs/ -api: /api/ +# api: /api/ news: /news/ plugins: /plugins/ themes: /themes/ \ No newline at end of file diff --git a/source/docs/asset-folders.md b/source/docs/asset-folders.md new file mode 100644 index 0000000000..48da17ec17 --- /dev/null +++ b/source/docs/asset-folders.md @@ -0,0 +1,19 @@ +title: Asset Folders +--- +Assets are non-post files in `source` folder, such as images, CSS or JavaScript files. Hexo provides a more convenient way to manage assets. To enable this, modify `post_asset_folder` setting. + +``` yaml +post_asset_folder: true +``` + +Once `post_asset_folder` setting is enabled, Hexo will create a folder with the same name as the new post. You can put all assets related to the post into the folder. So that you can use them more easily. + +## Tag Plugins + +Several tag plugins are added in Hexo 3 for you to include assets in posts more easily. + +``` +{% asset_path slug %} +{% asset_img slug %} +{% asset_link slug [title] %} +``` \ No newline at end of file diff --git a/source/docs/cli-clean.md b/source/docs/cli-clean.md deleted file mode 100644 index 0b15717319..0000000000 --- a/source/docs/cli-clean.md +++ /dev/null @@ -1,7 +0,0 @@ -title: Clean ---- -This command is used to delete all generated files and cache (`db.json`). - -``` bash -$ hexo clean -``` \ No newline at end of file diff --git a/source/docs/cli-config.md b/source/docs/cli-config.md deleted file mode 100644 index 40faa3c061..0000000000 --- a/source/docs/cli-config.md +++ /dev/null @@ -1,27 +0,0 @@ -title: Manage configuration ---- -This command is used to manage configuration of Hexo. - -``` bash -$ hexo config [key] [value] -``` - -## List - -``` bash -$ hexo config -``` - -### Get - -``` bash -$ hexo config -``` - -### Set - -``` bash -$ hexo config -``` - -When `value` is `null`, the `key` will be deleted. \ No newline at end of file diff --git a/source/docs/cli-deploy.md b/source/docs/cli-deploy.md deleted file mode 100644 index 322867c988..0000000000 --- a/source/docs/cli-deploy.md +++ /dev/null @@ -1,144 +0,0 @@ -title: Deployment ---- -This command is used to deploy your site to remote services. - -``` bash -$ hexo deploy -``` - -## Settings - -Before you start deployment, you have to configure deployment settings in `_config.yml`. A valid deployment setting must have `type` at least. - -``` yaml -deploy: - type: git -``` - -You can set multiple deployers in settings. Hexo will run each deployer in order. - -``` yaml -deploy: -- type: git - repo: -- type: heroku - repo: -``` - -## Git - -### Install - -``` bash -$ npm install hexo-deployer-git --save -``` - -### Settings - -``` yaml -deploy: - type: git - repo: - branch: [branch] - message: [message] -``` - -Option | Description | Default ---- | --- | --- -`repo` | Git repository URL (Better to use HTTPS) | -`branch` | Branch setting. This deployer will detect the branch automatically if you use GitHub or GitCafe. | master -`message` | Customize commit message | `{% raw %}{{ now('YYYY-MM-DD HH:mm:ss') }}{% endraw %}` - -### Remove - -``` bash -$ rm -rf .deploy_git -``` - -## Heroku - -### Install - -``` bash -$ npm install hexo-deployer-heroku --save -``` - -### Settings - -``` yaml -deploy: - type: heroku - repo: - message: [message] -``` - -Option | Description | Default ---- | --- | --- -`repo` | Git repository URL (Better to use HTTPS) | -`message` | Customize commit message | `{% raw %}{{ now('YYYY-MM-DD HH:mm:ss') }}{% endraw %}` - -### Remove - -``` bash -$ rm -rf .deploy_heroku -``` - -## OpenShift - -### Install - -``` bash -$ npm install hexo-deployer-openshift --save -``` - -### Settings - -``` yaml -deploy: - type: openshift - repo: - message: [message] -``` - -Option | Description | Default ---- | --- | --- -`repo` | Git repository URL (Better to use HTTPS) | -`message` | Customize commit message | `{% raw %}{{ now('YYYY-MM-DD HH:mm:ss') }}{% endraw %}` - -### Remove - -``` bash -$ rm -rf .deploy_openshift -``` - -## Rsync - -### Install - -``` bash -$ npm install hexo-deployer-rsync --save -``` - -### Settings - -``` yaml -deploy: - type: rsync - host: - user: - root: - port: [port] - delete: [true|false] - verbose: [true|false] - ignore_errors: [true|false] -``` - -Option | Description | Default ---- | --- | --- -`host` | Address of remote host | -`user` | Username | -`root` | Root directory of remote host | -`port` | Port | 22 -`delete` | Delete old files on remote host | true -`verbose` | Display verbose messages | true -`ignore_errors` | Ignore errors | false \ No newline at end of file diff --git a/source/docs/cli-generate.md b/source/docs/cli-generate.md deleted file mode 100644 index 4d1620259d..0000000000 --- a/source/docs/cli-generate.md +++ /dev/null @@ -1,24 +0,0 @@ -title: Generate ---- -This command is used to generate static files to public folder. - -``` bash -$ hexo generate -``` - -### Watching - -Watch for file changes and regenerate files immediately. Only modified files will be regenerated. But `_config.yml` won't be watched. You have to restart Hexo to make the new configurations take effects. - -``` bash -$ hexo generate --watch -``` - -### Deploy After Generating - -To deploy after generating, you can run one of the following commands. Both of them are equaled. - -``` bash -$ hexo generate --deploy -$ hexo deploy --generate -``` \ No newline at end of file diff --git a/source/docs/commands.md b/source/docs/commands.md index 53bcb3ab99..6569c3ff96 100644 --- a/source/docs/commands.md +++ b/source/docs/commands.md @@ -16,8 +16,6 @@ $ hexo new [layout] Creates a new article. If `layout` isn't defined, it'll equal the `default_layout` setting in [_config.yml](configuration.html). If the title is more than one word, wrap it with quotation marks. -**Alias:** n - ## generate ``` bash @@ -26,8 +24,6 @@ $ hexo generate Generates static files. -**Alias**: g - Option | Description --- | --- `-d`, `--deploy` | Deploy after generate done @@ -41,8 +37,6 @@ $ hexo publish [layout] <filename> Publishes a draft. -**Alias**: p - ## server ``` bash @@ -51,14 +45,11 @@ $ hexo server Starts server. -**Alias:** s - Option | Description --- | --- `-p`, `--port` | Override default port `-s`, `--static` | Only serve static files `-l`, `--log` | Enable logger. Override logger format. -`-d`, `--drafts` | Serve drafts as normal posts. ## deploy @@ -68,13 +59,9 @@ $ hexo deploy Deploys your website. -**Alias:** d - Option | Description --- | --- -`--setup` | Setup without deployment `-g`, `--generate` | Generate before deployment -`-m`, `--message` | Customize commit message ## render @@ -153,3 +140,19 @@ $ hexo --config custom.yml ``` Customize config file path instead of `_config.yml`. + +### Display drafts + +``` bash +$ hexo --draft +``` + +Display draft posts in `source/_drafts` folder. + +### Customize CWD + +``` bash +$ hexo --cwd /path/to/cwd +``` + +Customize the path of current working directory. \ No newline at end of file diff --git a/source/docs/configuration.md b/source/docs/configuration.md index 7ef5b510bf..ab3ef4f679 100644 --- a/source/docs/configuration.md +++ b/source/docs/configuration.md @@ -1,8 +1,6 @@ title: Configuration --- -You can modify most options in `_config.yml`. - -## Configuration +You can modify most settings in `_config.yml`. ### Site @@ -51,7 +49,7 @@ Setting | Description | Default `external_link` | Open external links in new tab | true `filename_case` | Transform filename into (1) lower case or (2) upper case | 0 `render_drafts` | Display drafts | false -`post_asset_folder` | Enables [Asset Folder](writing.html#Asset_Folder) | false +`post_asset_folder` | Enables [Asset Folder](asset-folders.html) | false `relative_link` | Make links relative to root folder | false `future` | Display future posts | true `highlight` | Code block settings | diff --git a/source/docs/contributing.md b/source/docs/contributing.md index 63999d538e..7998c925c0 100644 --- a/source/docs/contributing.md +++ b/source/docs/contributing.md @@ -2,7 +2,7 @@ title: Contributing --- ## Development -Hexo welcomes you to join the development of Hexo. This document will help you through the process. +We welcome you to join the development of Hexo. This document will help you through the process. ### Before You Start @@ -14,71 +14,78 @@ Please follow the coding style: ### Workflow -1. Fork the project. +1. Fork [hexojs/hexo]. 2. Clone the repository to your computer and install dependencies. - ``` bash + {% code %} $ git clone https://github.com/<username>/hexo.git $ cd hexo $ npm install $ git submodule update --init - ``` + {% endcode %} -3. Create a feature branch for your change. +3. Create a feature branch. - ``` bash + {% code %} $ git checkout -b new_feature - ``` + {% endcode %} -4. Start hacking. Don't forget to run tests. +4. Start hacking. 5. Push the branch: - ``` bash + {% code %} $ git push origin new_feature - ``` + {% endcode %} -6. Create a pull request against the `master` branch and describe the change. +6. Create a pull request and describe the change. -{% note warn Don't change version in package.json %} -When making changes on Hexo, don't change version number in `package.json`. -{% endnote %} +### Notice + +- Don't modify version number in `package.json`. +- Your pull request will only get merged when tests passed. Don't forget to run tests before submission. + + {% code %} + $ npm test + {% endcode %} ## Updating Documentation -The Hexo documentation is open source and you can find the source code on [hexojs/site](https://github.com/hexojs/site). To update the documentation: +The Hexo documentation is open source and you can find the source code on [hexojs/site]. -1. Fork the project +### Workflow + +1. Fork [hexojs/site] 2. Clone the repository to your computer and install dependencies. - ``` bash + {% code %} $ git clone https://github.com/<username>/site.git $ cd site $ npm install - ``` + {% endcode %} 3. Start editing the documentation. You can start the server for live previewing. - ``` bash + {% code %} $ hexo server - ``` + {% endcode %} -4. Push the branch: -5. Create a pull request against the `master` branch and describe the change. +4. Push the branch. +5. Create a pull request and describe the change. -## Reporting Issues +### Translating -When you encounter some problems when using Hexo, you can find the solutions in [Troubleshooting] or ask me on [GitHub](https://github.com/hexojs/hexo/issues) or [Google Group](https://groups.google.com/group/hexo). If you can't find the answer, please report it on GitHub. +1. Add a new language folder in `source` folder. (All lower case) +2. Copy Markdown and template files in `source` folder to the new language folder. +3. Add the new language to `source/_data/language.yml`. +4. Copy `en.yml` in `themes/navy/languages` and rename to the language name (all lower case). -1. Represent the problem in debug mode. +## Reporting Issues - ``` bash - $ hexo --debug - ``` +When you encounter some problems when using Hexo, you can find the solutions in [Troubleshooting] or ask me on [GitHub](https://github.com/hexojs/hexo/issues) or [Google Group](https://groups.google.com/group/hexo). If you can't find the answer, please report it on GitHub. -2. Check the version info. +1. Represent the problem in [debug mode](commands.html#Debug_mode). +2. Run `hexo version` and check the version info. +3. Post both debug message and version info on GitHub. - ``` bash - $ hexo version - ``` - -3. Post both debug message and version info on GitHub. \ No newline at end of file +[hexojs/hexo]: https://github.com/hexojs/hexo +[hexojs/site]: https://github.com/hexojs/site \ No newline at end of file diff --git a/source/docs/data-files.md b/source/docs/data-files.md new file mode 100644 index 0000000000..db6a9d16c7 --- /dev/null +++ b/source/docs/data-files.md @@ -0,0 +1,19 @@ +title: Data Files +--- +Sometimes you may need to use some data in templates which is not in posts, or you want to reuse these data. Then you can try the new "**Data files**" introducing in Hexo 3. This feature loads YAML or JSON files in `source/_data` folder so you can use them in your site. + +For example, add `menu.yml` in `source/_data` folder. + +``` yaml +Home: / +Gallery: /gallery/ +Archives: /archives/ +``` + +And you can use them in templates: + +``` +{% for link in site.data.menu %} + <a href="{{ link }}">{{ loop.key }}</a> +{% endfor %} +``` \ No newline at end of file diff --git a/source/docs/deployment.md b/source/docs/deployment.md index 6827dcdf36..f7c84101a9 100644 --- a/source/docs/deployment.md +++ b/source/docs/deployment.md @@ -1,53 +1,61 @@ title: Deployment --- -To deploy your site with Hexo, you only need one command. +Hexo provides a fasy and easy way for deployment. You only need one command to deploy your site to servers. ``` bash $ hexo deploy ``` -## GitHub Pages - -Edit `_config.yml`. +Before we start, you have to modify settings in `_config.yml`. A valid deployment setting must come with `type` field. For example: ``` yaml deploy: - type: github - repo: <repository url> - branch: [branch] - message: [message] + type: git ``` -Option | Description ---- | --- -`repo`, `repository` | GitHub repository URL (Better to use HTTPS) -`branch` | The deployer will detect the branch to use automatically. You can also customize it on your own. -`message` | Customize commit message (Default is `Site updated: {% raw %}{{ now('YYYY-MM-DD HH:mm:ss') }}{% endraw %}`) +You can use multiple deployers. Hexo will execute each deployer in sequence. + +``` yaml +deployer: +- type: git + repo: +- type: heroku + repo: +``` -### Remove +## Git -Remove `.deploy` folder. +Install [hexo-deployer-git]. ``` bash -$ rm -rf .deploy +$ npm install hexo-deployer-git --save ``` -### Custom Domain +Edit settings. -Create a file named `CNAME` in `source` folder with the following content. - -``` plain -example.com +``` yaml +deploy: + type: git + repo: <repository url> + branch: [branch] + message: [message] ``` -- **Top-level Domain:** Add A records: `192.30.252.153`, `192.30.252.154`. -- **Subdomain**: Add a CNAME record `blog.example.com`. - -Check [GitHub Pages](https://help.github.com/articles/setting-up-a-custom-domain-with-pages) for more info. +Option | Description +--- | --- +`repo` | GitHub repository URL +`branch` | Branch name. The deployer will detect branch automatically if you are using GitHub or GitCafe. +`message` | Customize commit message (Default to `Site updated: {% raw %}{{ now('YYYY-MM-DD HH:mm:ss') }}{% endraw %}`) ## Heroku -Edit `_config.yml`. +Install [hexo-deployer-heroku]. + +``` bash +$ npm install hexo-deployer-heroku --save +``` + +Edit settings. ``` yaml deploy: @@ -59,15 +67,17 @@ deploy: Option | Description --- | --- `repo`, `repository` | Heroku repository URL -`message` | Customize commit message (Default is `Site updated: {% raw %}{{ now('YYYY-MM-DD HH:mm:ss') }}{% endraw %}`) +`message` | Customize commit message (Default to `Site updated: {% raw %}{{ now('YYYY-MM-DD HH:mm:ss') }}{% endraw %}`) -### Remove +## Rsync -Remove `.git`, `app.js` & `Procfile`. +Install [hexo-deployer-rsync]. -## Rsync +``` bash +$ npm install hexo-deployer-rsync --save +``` -Edit `_config.yml`. +Edit settings. ``` yaml deploy: @@ -91,78 +101,33 @@ Option | Description | Default `verbose` | Display verbose messages | true `ignore_errors` | Ignore errors | false -## OpenShift DIY Cartridge +## OpenShift -Edit `_config.yml`. +Install [hexo-deployer-openshift]. -``` yaml -deploy: - type: openshift - remote: <upstream git remote> - branch: [upstream git branch] # Default is master +``` bash +$ npm install hexo-deployer-openshift --save ``` -Option | Description | Default ---- | --- | --- -`remote` | Upstream Git remote | -`branch` | Upstream Git branch | master - -## Git - -Edit `_config.yml`. +Edit settings. ``` yaml deploy: - type: git + type: openshift + repo: <repository url> message: [message] - repo: - github: <repository url>,[branch] - gitcafe: <repository url>,[branch] ``` Option | Description ---- | --- | --- -`repo`, `repository` | Repository URL and branch. Separated with a comma (`,`). The branch is `master` by default. -`message` | Customize commit message (Default is `Site updated: {% raw %}{{ now('YYYY-MM-DD HH:mm:ss') }}{% endraw %}`) - -## Batch Deploy - -You can deploy your site to multiple destinations. - -``` yaml -deploy: -- type: github - repo: ... -- type: heroku - repo: ... -``` - -## Commit message - -You can customize commit message in **github**, **heroku**, **git** deployer. - -Swig is availble in commit message. You can use `now(format)` to display deployment time. For example, the default message is `Site updated: {% raw %}{{ now('YYYY-MM-DD HH:mm:ss') }}{% endraw %}`: - -``` js -Site updated: {% raw %}{{ now('YYYY-MM-DD HH:mm:ss') }}{% endraw %} -// Site updated: 2014-05-12 00:02:25 -``` - -Commit message can be set either in shell - -``` bash -$ hexo deploy -m "Commit message" -``` - -or in `_config.yml`. - -``` yaml -deploy: - type: github - repo: ... - message: "Commit message" -``` +--- | --- +`repo` | OpenShift repository URL +`message` | Customize commit message (Default to `Site updated: {% raw %}{{ now('YYYY-MM-DD HH:mm:ss') }}{% endraw %}`) ## Other Methods All generated files are saved in `public` folder. You can copy it to wherever you like. + +[hexo-deployer-git]: https://github.com/hexojs/hexo-deployer-git +[hexo-deployer-heroku]: https://github.com/hexojs/hexo-deployer-heroku +[hexo-deployer-rsync]: https://github.com/hexojs/hexo-deployer-rsync +[hexo-deployer-openshift]: https://github.com/hexojs/hexo-deployer-openshift \ No newline at end of file diff --git a/source/docs/drafts.md b/source/docs/drafts.md deleted file mode 100644 index 7c7a5fe20d..0000000000 --- a/source/docs/drafts.md +++ /dev/null @@ -1,35 +0,0 @@ -title: Drafts ---- -## Creating - -You can create a draft by using `hexo new` command. For example: - -``` bash -$ hexo new draft <title> -``` - -Files will be saved in `source/_drafts` folder. - -## Previewing - -To preview your site with drafts, you can enable `render_drafts` setting in `_config.yml`: - -``` yaml -render_drafts: true -``` - -or run `hexo server` with `-d` or `--drafts` flag. - -``` bash -$ hexo server --drafts -``` - -## Publishing - -Once your draft is done, you can publish it with `hexo publish` command. - -``` bash -$ hexo publish [layout] <filename> -``` - -Files will be moved to `source/_posts` folder and applied with the layout you specified in the command. \ No newline at end of file diff --git a/source/docs/events.md b/source/docs/events.md deleted file mode 100644 index d990f81f64..0000000000 --- a/source/docs/events.md +++ /dev/null @@ -1,66 +0,0 @@ -title: Events ---- -## Overview - -Hexo inherits EventEmitter of Node.js. You can subscribe or publish specified events. For example: - -``` js -hexo.on('ready', function(){ - console.log('Hexo is ready to go!'); -}); -``` - -## Events - -### ready - -Called once Hexo is initialized. - -### generateBefore - -Called before generating. - -### generateAfter - -Called after generating. - -### processBefore - -Called before processing. - -Argument | Description ---- | --- -`path` | Base path of the processor - -### processAfter - -Called after processing. - -Argument | Description ---- | --- -`path` | Base path of the processor - -### new - -Called after a new post file is created. - -Argument | Description ---- | --- -`path` | Absolute path of the post file -`content` | Content of the post file - -### server - -Called after server is on. - -### exit - -Called when Hexo exits. - -### deployBefore - -Called before deployment. - -### deployAfter - -Called after deployment. \ No newline at end of file diff --git a/source/docs/first-post.md b/source/docs/first-post.md deleted file mode 100644 index 59a9217541..0000000000 --- a/source/docs/first-post.md +++ /dev/null @@ -1,77 +0,0 @@ -title: First Post ---- -You can create a new post by yourself or run the following command. If `layout` isn't defined, it'll be the `default_layout` setting. If there're spaces or other special characters in `title`, wrap it with quotation marks. - -``` bash -$ hexo new [layout] <title> -``` - -## Layout - -Hexo has 2 default layouts: `post` and `page`. Other layouts will be saved in `source/_posts` by default. - -Layout | Destination ---- | --- -`post` (Default) | source/_posts -`page` | source - -{% note tip Don't process my posts! %} -If you don't want your posts processed, you can set `layout: false` in front-matter. -{% endnote %} - -### Example - -``` bash -$ hexo new "New Post" -# => The file will be created at source/_posts/new-post.md - -$ hexo new page "New Page" -# => The file will be created at source/new-page/index.html -``` - -## Filename - -You can modify the name of files created by Hexo in `new_post_name` setting. - -Variable | Description ---- | --- -`:title` | Escaped title (lower case and replace spaces with dash) -`:year` | Created year (4-digit) -`:month` | Created month (2-digit) -`:i_month` | Created month (Without leading zeros) -`:day` | Created day (2-digit) -`:i_day` | Created day (Without leading zeros) - -{% note tip Organize your posts by date %} -You can set `new_post_name` as `:year-:month-:day-:title.md` to make your posts ordered by date. -{% endnote %} - -## Scaffold - -Hexo will create a new post based on the correspond scaffold. For example: - -``` bash -$ hexo new photo "My Gallery" -# => The file will be created at source/_posts/my-gallery.md -``` - -Hexo will find the scaffold file named `photo` in the `scaffolds` folder. If the scaffold not exists, use the post scaffold instead. - -### Example - -Variables are wrapped by double curly brackets. For example: - -``` plain -layout: {% raw %}{{ layout }}{% endraw %} -title: {% raw %}{{ title }}{% endraw %} -date: {% raw %}{{ date }}{% endraw %} ---- -``` - -### Variables - -Variable | Description ---- | --- -`layout` | Layout name -`title` | Post title -`date` | File created date \ No newline at end of file diff --git a/source/docs/front-matter.md b/source/docs/front-matter.md index 95231fcc24..69fc35e359 100644 --- a/source/docs/front-matter.md +++ b/source/docs/front-matter.md @@ -1,7 +1,5 @@ title: Front-matter --- -## Front-matter - Front-matter is a block wrapped with `---` in front of the file. For example: ``` yaml @@ -14,15 +12,33 @@ You can configure all post configuration in the front-matter. The following is p Setting | Description | Default --- | --- | --- -`layout` | Layout | post/page +`layout` | Layout | `title` | Title | `date` | Published date | File created date -`updated` | Last updated date | File last updated date +`updated` | Updated date | File updated date `comments` | Enables comment feature for the post | true `tags` | Tags (Not available for pages) | `categories` | Categories (Not available for pages) | -`permalink` | Overrides the default permalink of the post | Filename +`permalink` | Overrides the default permalink of the post | + +### Categories & Tags + +Categories and tags are only supported in posts. You can set them in front-matter. In other systems, categories and tags may sound fimiliar, but there's a definitive difference between them: categories are orderly and inherited, which means `Foo, Bar` doesn't equal to `Bar, Foo`; while tags don't have order and inhertiance. + +``` yaml +categories: +- Diary +tags: +- PS3 +- Games +``` + +### JSON Front-matter + +Besides YAML, you can write front-matter with JSON. Just replace `---` with `;;;`. -{% note warn YAML front-matter %} -Write the front-matter in YAML format. Don't use tabs in the front-matter, use spaces instead. Also, add a space after colons. -{% endnote %} \ No newline at end of file +``` json +"title": "Hello World", +"date": "2013/7/13 20:46:25" +;;; +``` \ No newline at end of file diff --git a/source/docs/generating.md b/source/docs/generating.md index 84e071e51f..67c19f5552 100644 --- a/source/docs/generating.md +++ b/source/docs/generating.md @@ -8,16 +8,12 @@ $ hexo generate ### Watch for File Changes -Hexo can watch for file changes and regenerate files immediately. +Hexo can watch for file changes and regenerate files immediately. Hexo will compare SHA1 checksum of files and only write if files changed. ``` bash $ hexo generate --watch ``` -{% note info Restart Hexo after configuration changed %} -Hexo doesn't watch for configuration file changes. You have to restart Hexo to make the new configurations take effects. -{% endnote %} - ### Deploy After Generating To deploy after generating, you can run one of the following commands. Both of them are equaled. diff --git a/source/docs/helpers.md b/source/docs/helpers.md index 0d40fc54eb..842238fdc2 100644 --- a/source/docs/helpers.md +++ b/source/docs/helpers.md @@ -1,6 +1,8 @@ title: Helpers --- -Helpers are used in templates to help you insert snippets quickly. You can see [Plugins](plugins.html#Helper) to learn how to build a helper plugin. +Helpers are used in templates to help you insert snippets quickly. + +## URL ### url_for @@ -12,12 +14,32 @@ Returns a url with the root path prefixed. You should use this helper instead of ### relative_url -Solves the relative URL from `from` to `to`. +Returns the relative URL from `from` to `to`. ``` js <%- relative_url(from, to) %> ``` +### gravatar + +Inserts a Gravatar image. + +``` js +<%- gravatar(email, [size]); +``` + +**Examples:** + +``` js +<%- gravatar('a@abc.com') %> +// http://www.gravatar.com/avatar/b9b00e66c6b8a70f88c73cb6bdb06787 + +<%- gravatar('a@abc.com', 40) %> +// http://www.gravatar.com/avatar/b9b00e66c6b8a70f88c73cb6bdb06787?s=40 +``` + +## HTML Tags + ### css Loads CSS files. `path` can be an array or a string. If `path` isn't prefixed with `/` or any protocol, it'll be prefixed with root URL. If you didn't add extension name `.css` after `path`, it'll be added. @@ -56,235 +78,203 @@ Loads JavaScript files. `path` can be an array or a string. If `path` isn't pref // <script type="text/javascript" src="/gallery.js"></script> ``` -### Conditional Tags - -Conditional tags help you check the status of current page. - -Helper | Description ---- | --- -`is_current(path, [strict])` | Checks if `path` matches the URL of current page. -`is_home()` | Checks if the home page is being displayed -`is_post()` | Checks if posts are being displayed -`is_archive()` | Checks if archive pages are being displayed -`is_year()` | Checks if yearly archive pages are being displayed -`is_month()` | Checks if monthly archive pages are being displayed -`is_category()` | Checks if category pages are being displayed -`is_tag()` | Checks if tag pages are being displayed - -### gravatar +### link_to -Inserts a Gravatar image. +Inserts a link. ``` js -<%- gravatar(email, [size]); +<%- link_to(path, [text], [options]) %> ``` +Option | Description | Default +--- | --- | --- +`external` | Opens the link in a new tab | false +`class` | Class name | +`id` | ID | + **Examples:** ``` js -<%- gravatar('a@abc.com') %> -// http://www.gravatar.com/avatar/b9b00e66c6b8a70f88c73cb6bdb06787 - -<%- gravatar('a@abc.com', 40) %> -// http://www.gravatar.com/avatar/b9b00e66c6b8a70f88c73cb6bdb06787?s=40 -``` - -### trim +<%- link_to('http://www.google.com') %> +// <a href="http://www.google.com" title="http://www.google.com">http://www.google.com</a> -Clears all spaces in a string. +<%- link_to('http://www.google.com', 'Google') %> +// <a href="http://www.google.com" title="Google">Google</a> -``` js -<%- trim(string) %> +<%- link_to('http://www.google.com', 'Google', {external: true}) %> +// <a href="http://www.google.com" title="Google" target="_blank" rel="external">Google</a> ``` -### strip_html +### mail_to -Sanitizes all HTML tags in a string. +Inserts a mail link. ``` js -<%- strip_html(string) %> +<%- mail_to(path, [text], [options]) %> ``` +Option | Description +--- | --- +`class` | Class name +`id` | ID +`subject` | Mail subject +`cc` | CC +`bcc` | BCC +`body` | Mail contents + **Examples:** ``` js -<%- strip_html('It's not <b>important</b> anymore!') %> -// It's not important anymore! +<%- mail_to('a@abc.com') %> +// <a href="mailto:a@abc.com" title="a@abc.com">a@abc.com</a> + +<%- mail_to('a@abc.com', 'Email') %> +// <a href="mailto:a@abc.com" title="Email">Email</a> ``` -### titlecase +### image_tag -Transforms a string into proper title caps. +Inserts a image. ``` js -<%- titlecase(string) %> +<%- image_tag(path, [options]) %> ``` -**Examples:** +Option | Description +--- | --- +`alt` | Alternative text of the image +`class` | Class name +`id` | ID +`width` | Image width +`height` | Image height + +### favicon_tag + +Inserts a favicon. ``` js -<%- titlecase('this is an apple') %> -# This is an Apple +<%- favicon_tag(path) %> ``` -### partial +### feed_tag -Loads other template files. You can define local variables in `locals`. +Inserts a feed link. ``` js -<%- partial(layout, [locals], [options]) %> +<%- feed_tag(path, [options]) %> ``` Option | Description | Default --- | --- | --- -`cache` | Cache contents | `false` -`only` | Strict local variables | `false` +`title` | Feed title | +`type` | Feed type | atom -### fragment_cache +### Conditional Tags -Caches the contents in a fragment. It saves the contents within a fragment and serves the cache when the next request comes in. +### is_current -``` js -<%- fragment_cache(id, fn); -``` - -**Examples:** +Check whether `path` matches the URL of the current page. Use `strict` options to enable strict matching. ``` js -<%- fragment_cache('header', function(){ - return '<header></header>'; -}) %> +<%- is_current(path, [strict] %> ``` -### tagcloud +### is_home -Inserts a tag cloud. +Check whether the current page is home page. ``` js -<%- tagcloud([tags], [options]) %> +<%- is_home() %> ``` -Option | Description | Default ---- | --- | --- -`min_font` | Minimal font size | 10 -`max_font` | Maximum font size | 20 -`unit` | Unit of font size | px -`amount` | Total amount of tags | 40 -`orderby` | Order of tags | name -`order` | Sort order. `1`, `sac` as ascending; `-1`, `desc` as descending | 1 -`color` | Colorizes the tag cloud | false -`start_color` | Start color. You can use hex (`#b700ff`), rgba (`rgba(183, 0, 255, 1)`), hsla (`hsla(283, 100%, 50%, 1)`) or [color keywords]. This option only works when `color` is true. | -`end_color` | End color. You can use hex (`#b700ff`), rgba (`rgba(183, 0, 255, 1)`), hsla (`hsla(283, 100%, 50%, 1)`) or [color keywords]. This option only works when `color` is true. | - -### paginator +### is_post -Inserts a paginator. +Check whether the current page is a post. ``` js -<%- paginator(options) %> +<%- is_post() %> ``` -Option | Description | Default ---- | --- | --- -`base` | Base URL | / -`format` | URL format | page/%d/ -`total` | Total amount of pages | 1 -`current` | Current page number | 0 -`prev_text` | The link text of previous page. Works only if `prev_next` is set to true. | Prev -`next_text` | The link text of next page. Works only if `prev_next` is set to true. | Next -`space` | The space text | &hellp; -`prev_next` | Display previous and next links | true -`end_size` | The number of pages displayed on the start and the end side | 1 -`mid_size` | The number of pages displayed between current page, but not including current page | 2 -`show_all` | Display all pages. If this is set true, `end_size` and `mid_size` will not works. | false - -### date +### is_archive -Inserts formatted date. `date` can be unix time, ISO string, date object, or moment.js object. `format` is `date_format` setting by default. +Check whether the current page is a archive page. ``` js -<%- date(date, [format]) %> +<%- is_archive() %> ``` -**Examples:** +### is_year -``` js -<%- date(Date.now()) %> -// Jan 1, 2013 +Check whether the current page is a yearly archive page. -<%- date(Date.now(), 'YYYY/M/D') %> -// 2013/1/1 +``` js +<%- is_year() %> ``` -### date_xml +### is_month -Inserts date in XML format. `date` can be unix time, ISO string, date object, or moment.js object. `format` is `date_format` setting by default. +Check whether the current page is a monthly archive page. ``` js -<%- date_xml(date) %> +<%- is_month() %> ``` -**Examples:** +### is_category + +Check whether the current page is a category page. ``` js -<%- date_xml(Date.now()) %> -// 2013-01-01T00:00:00.000Z +<%- is_category() %> ``` -### time +### is_tag -Inserts formatted time. `date` can be unix time, ISO string, date object, or moment.js object. `format` is `time_format` setting by default. +Check whether the current page is a tag page. ``` js -<%- time(date, [format]) %> +<%- is_tag() %> ``` -**Examples:** +## String Manipulating -``` js -<%- time(Date.now()) %> -// 13:05:12 +### trim -<%- time(Date.now(), 'h:mm:ss a') %> -// 1:05:12 pm +Removes prefixing and trailing spaces of a string. + +``` js +<%- trim(string) %> ``` -### full_date +### strip_html -Inserts formatted date and time. `date` can be unix time, ISO string, date object, or moment.js object. `format` is `date_format + time_format` setting by default. +Sanitizes all HTML tags in a string. ``` js -<%- full_date(date, [format]) %> +<%- strip_html(string) %> ``` **Examples:** ``` js -<%- full_date(new Date()) %> -// Jan 1, 2013 0:00:00 - -<%- full_date(new Date(), 'dddd, MMMM Do YYYY, h:mm:ss a') %> -// Tuesday, January 1st 2013, 12:00:00 am +<%- strip_html('It's not <b>important</b> anymore!') %> +// It's not important anymore! ``` -### moment +### titlecase -[Moment.js] library. +Transforms a string into proper title caps. -### search_form +``` js +<%- titlecase(string) %> +``` -Inserts a Google search form. +**Examples:** ``` js -<%- search_form(options) %> +<%- titlecase('this is an apple') %> +# This is an Apple ``` -Option | Description | Default ---- | --- | --- -`class` | The class name of form | search-form -`text` | Search hint word | Search -`button` | Display search button. The value can be a boolean or a string. When the value is a string, it'll be the text of the button. | false - ### markdown Renders a string with Markdown. @@ -300,6 +290,14 @@ Renders a string with Markdown. // make me <strong>strong</strong> ``` +### render + +Renders a string. + +``` js +<%- render(str, engine, [options]) %> +``` + ### word_wrap Wraps text into lines no longer than `length`. `length` is 80 by default. @@ -330,111 +328,113 @@ Truncates text after `length`. // Once upon a time ``` -### truncate_words +## Templates -Truncates words after `length`. +### partial + +Loads other template files. You can define local variables in `locals`. ``` js -<%- truncate_words(text, length) %> +<%- partial(layout, [locals], [options]) %> +``` + +Option | Description | Default +--- | --- | --- +`cache` | Cache contents (Use fragment cache) | `false` +`only` | Strict local variables. Only use variables set in `locals` in templates. | `false` + +### fragment_cache + +Caches the contents in a fragment. It saves the contents within a fragment and serves the cache when the next request comes in. + +``` js +<%- fragment_cache(id, fn); ``` **Examples:** ``` js -<%- truncate_words('Once upon a time in a world far far away', 4) %> -// Once upon a time +<%- fragment_cache('header', function(){ + return '<header></header>'; +}) %> ``` -### link_to +## Date & Time -Inserts a link. +### date + +Inserts formatted date. `date` can be unix time, ISO string, date object, or [Moment.js] object. `format` is `date_format` setting by default. ``` js -<%- link_to(path, [text], [options]) %> +<%- date(date, [format]) %> ``` -Option | Description | Default ---- | --- | --- -external | Opens the link in a new tab | false -class | Class name | -id | ID | - **Examples:** ``` js -<%- link_to('http://www.google.com') %> -// <a href="http://www.google.com" title="http://www.google.com">http://www.google.com</a> - -<%- link_to('http://www.google.com', 'Google') %> -// <a href="http://www.google.com" title="Google">Google</a> +<%- date(Date.now()) %> +// 2013-01-01 -<%- link_to('http://www.google.com', 'Google', {external: true}) %> -// <a href="http://www.google.com" title="Google" target="_blank" rel="external">Google</a> +<%- date(Date.now(), 'YYYY/M/D') %> +// Jan 1 2013 ``` -### mail_to +### date_xml -Inserts a mail link. +Inserts date in XML format. `date` can be unix time, ISO string, date object, or [Moment.js] object. ``` js -<%- mail_to(path, [text], [options]) %> +<%- date_xml(date) %> ``` -Option | Description ---- | --- -class | Class name -id | ID -subject | Mail subject -cc | CC -bcc | BCC -body | Mail contents - **Examples:** ``` js -<%- mail_to('a@abc.com') %> -// <a href="mailto:a@abc.com" title="a@abc.com">a@abc.com</a> - -<%- mail_to('a@abc.com', 'Email') %> -// <a href="mailto:a@abc.com" title="Email">Email</a> +<%- date_xml(Date.now()) %> +// 2013-01-01T00:00:00.000Z ``` -### image_tag +### time -Inserts a image. +Inserts formatted time. `date` can be unix time, ISO string, date object, or [Moment.js] object. `format` is `time_format` setting by default. ``` js -<%- image_tag(path, [options]) %> +<%- time(date, [format]) %> ``` -Option | Description ---- | --- -alt | Alternative text of the image -class | Class name -id | ID -width | Image width -height | Image height +**Examples:** -### favicon_tag +``` js +<%- time(Date.now()) %> +// 13:05:12 -Inserts a favicon. +<%- time(Date.now(), 'h:mm:ss a') %> +// 1:05:12 pm +``` + +### full_date + +Inserts formatted date and time. `date` can be unix time, ISO string, date object, or [Moment.js] object. `format` is `date_format + time_format` setting by default. ``` js -<%- favicon_tag(path) %> +<%- full_date(date, [format]) %> ``` -### feed_tag - -Inserts a feed link. +**Examples:** ``` js -<%- feed_tag(path, [options]) %> +<%- full_date(new Date()) %> +// Jan 1, 2013 0:00:00 + +<%- full_date(new Date(), 'dddd, MMMM Do YYYY, h:mm:ss a') %> +// Tuesday, January 1st 2013, 12:00:00 am ``` -Option | Description | Default ---- | --- | --- -title | Feed title | -type | Feed type | atom +### moment + +[Moment.js] library. + +## List ### list_categories @@ -447,12 +447,13 @@ Inserts a list of all categories. Option | Description | Default --- | --- | --- `orderby` | Order of categories | name -`order` | Sort of order. `1`, `asc` as ascending; `-1`, `desc` as descending | 1 -`show_count` | Display the total amount of posts for each category | true -`style` | Style to display the categories list. `list` displays categories in an unordered list. | list -`separator` | Separator between categories. (Only works if `style` is `none`) | , -`depth` | Levels of categories to be displayed. `0` displays all categories and child categories; `-1` is same as `0` but displayed in flat; `1` displays only top level categories. | 0 -`class` | Class name of categories list. | category +`order` | Sort of order. `1`, `asc` for ascending; `-1`, `desc` for descending | 1 +`show_count` | Display the number of posts for each category | true +`style` | Style to display the category list. `list` displays categories in an unordered list. | list +`separator` | Separator between categories. (Only works if `style` is not `list`) | , +`depth` | Levels of categories to be displayed. `0` displays all categories and child categories; `-1` is simliar to `0` but displayed in flat; `1` displays only top level categories. | 0 +`class` | Class name of category list. | category +`transform` | The function that changes the display of category name. | ### list_tags @@ -465,11 +466,12 @@ Inserts a list of all tags. Option | Description | Default --- | --- | --- `orderby` | Order of categories | name -`order` | Sort of order. `1`, `asc` as ascending; `-1`, `desc` as descending | 1 -`show_count` | Display the total amount of posts for each tag | true -`style` | Style to display the tags list. `list` displays tags in an unordered list. | list -`separator` | Separator between tags. (Only works if `style` is `none`) | , -`class` | Class name of tags list. | tag +`order` | Sort of order. `1`, `asc` for ascending; `-1`, `desc` for descending | 1 +`show_count` | Display the number of posts for each tag | true +`style` | Style to display the tag list. `list` displays tags in an unordered list. | list +`separator` | Separator between categories. (Only works if `style` is not `list`) | , +`class` | Class name of tag list. | tag +`transform` | The function that changes the display of category name. | `amount` | The number of tags to display (0 = unlimited) | 0 ### list_archives @@ -483,12 +485,13 @@ Inserts a list of archives. Option | Description | Default --- | --- | --- `type` | Type. This value can be `yearly` or `monthly`. | monthly -`order` | Sort of order. `1`, `asc` as ascending; `-1`, `desc` as descending | 1 -`show_count` | Display the total amount of posts for each archive | true +`order` | Sort of order. `1`, `asc` for ascending; `-1`, `desc` for descending | 1 +`show_count` | Display the number of posts for each archive | true `format` | Date format | MMMM YYYY -`style` | Style to display the archives list. `list` displays archives in an unordered list. | list -`separator` | Separator between archives. (Only works if `style` is `none`) | , -`class` | Class name of archives list. | category +`style` | Style to display the archive list. `list` displays archives in an unordered list. | list +`separator` | Separator between archives. (Only works if `style` is not `list`) | , +`class` | Class name of archive list. | archive +`transform` | The function that changes the display of archive name. | ### list_posts @@ -500,26 +503,71 @@ Inserts a list of posts. Option | Description | Default --- | --- | --- -`ulClass` | Class name of the container | -`liClass` | Class name of each item | -`style` | Style to display the post list. `list` displays posts in an unordered list. | list -`separator` | Separator between archives. (Only works if `style` is `none`) | , +`orderby` | Order of posts | date +`order` | Sort of order. `1`, `asc` for ascending; `-1`, `desc` for descending | 1 +`style` | Style to display the post list. `list` displays posts in an unordered list. | list +`separator` | Separator between posts. (Only works if `style` is not `list`) | , `class` | Class name of post list. | post +`amount` | The number of posts to display (0 = unlimited) | 6 +`transform` | The function that changes the display of post name. | -### get_posts +### tagcloud -Gets post data. +Inserts a tag cloud. ``` js -<% get_posts([options]) %> +<%- tagcloud([tags], [options]) %> ``` Option | Description | Default --- | --- | --- -`count` | The number of posts | 6 -`orderby` | Order of posts | date -`order` | Sort of order. `1`, `asc` as ascending; `-1`, `desc` as descending | -1 -`query` | Query conditions | +`min_font` | Minimal font size | 10 +`max_font` | Maximum font size | 20 +`unit` | Unit of font size | px +`amount` | Total amount of tags | 40 +`orderby` | Order of tags | name +`order` | Sort order. `1`, `sac` as ascending; `-1`, `desc` as descending | 1 +`color` | Colorizes the tag cloud | false +`start_color` | Start color. You can use hex (`#b700ff`), rgba (`rgba(183, 0, 255, 1)`), hsla (`hsla(283, 100%, 50%, 1)`) or [color keywords]. This option only works when `color` is true. | +`end_color` | End color. You can use hex (`#b700ff`), rgba (`rgba(183, 0, 255, 1)`), hsla (`hsla(283, 100%, 50%, 1)`) or [color keywords]. This option only works when `color` is true. | + +## Miscellaneous + +### paginator + +Inserts a paginator. + +``` js +<%- paginator(options) %> +``` + +Option | Description | Default +--- | --- | --- +`base` | Base URL | / +`format` | URL format | page/%d/ +`total` | The number of pages | 1 +`current` | Current page number | 0 +`prev_text` | The link text of previous page. Works only if `prev_next` is set to true. | Prev +`next_text` | The link text of next page. Works only if `prev_next` is set to true. | Next +`space` | The space text | &hellp; +`prev_next` | Display previous and next links | true +`end_size` | The number of pages displayed on the start and the end side | 1 +`mid_size` | The number of pages displayed between current page, but not including current page | 2 +`show_all` | Display all pages. If this is set true, `end_size` and `mid_size` will not works. | false + +### search_form + +Inserts a Google search form. + +``` js +<%- search_form(options) %> +``` + +Option | Description | Default +--- | --- | --- +`class` | The class name of form | search-form +`text` | Search hint word | Search +`button` | Display search button. The value can be a boolean or a string. When the value is a string, it'll be the text of the button. | false ### number_format @@ -556,7 +604,7 @@ Option | Description | Default ### open_graph -Inserts open graph data. +Inserts [Open Graph] data. ``` js <%- open_graph([options]) %> @@ -597,3 +645,5 @@ Option | Description | Default ``` [color keywords]: http://www.w3.org/TR/css3-color/#svg-color +[Moment.js]: http://momentjs.com/ +[Open Graph]: http://ogp.me/ \ No newline at end of file diff --git a/source/docs/index.md b/source/docs/index.md index c5b472bc48..a42f094767 100644 --- a/source/docs/index.md +++ b/source/docs/index.md @@ -20,7 +20,7 @@ Installing Hexo is quite easy. However, there are some things required before yo If your computer already has the requirements above, congratulations! Just install Hexo with npm. ``` bash -$ npm install -g hexo +$ npm install -g hexo-cli ``` If not, please follow the following instructions to install all the requirements. @@ -55,7 +55,7 @@ $ wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh Once installed, restart the terminal and run the following command to install Node.js. ``` bash -$ nvm install 0.10 +$ nvm install 0.12 ``` Or you can download the [installer](http://nodejs.org/) and install it. @@ -65,5 +65,5 @@ Or you can download the [installer](http://nodejs.org/) and install it. Once all the requirements are installed, you can install Hexo with npm. ``` bash -$ npm install -g hexo -``` +$ npm install -g hexo-cli +``` \ No newline at end of file diff --git a/source/docs/localization.md b/source/docs/localization.md new file mode 100644 index 0000000000..9423bbb1c4 --- /dev/null +++ b/source/docs/localization.md @@ -0,0 +1,55 @@ +title: Localization (i18n) +--- +You can use localization to present your site in different languages. Please edit `language` setting in `_config.yml`. This is your default language. You can also set multiple languages to modify the order of default languages. + +``` yaml +language: zh-tw + +language: +- zh-tw +- en +``` + +### Language Files + +Language files can be a YAML or JSON file. They should be put into the `languages` folder in the theme. You can use [printf format](https://github.com/alexei/sprintf.js) in language files. + +### Templates + +Use `__` or `_p` helpers in templates to get the translated strings. The former is for normal usage and the letter is for plural strings. For example: + +``` yaml en.yml +index: + title: Home + add: Add + video: + zero: No videos + one: One video + other: %d videos +``` + +``` js +<%= __('index.title') %> +// Home + +<%= _p('index.video', 3) %> +// 3 videos +``` + +### Path + +You can set the language of pages in front-matter, or modify `i18n_dir` setting in `_config.yml` to enable Hexo detect automatically. + +``` yaml +i18n_dir: :lang +``` + +The default value of `i18n_dir` setting is `:lang`, which means Hexo will detect the language with the first segment of URL. For example: + +``` plain +/index.html => en +/archives/index.html => en +/zh-tw/index.html => zh-tw +``` + +The string will only be served as a language when the language file exists. So `archives` in `/archives/index.html` (example 2) is not served as a language. \ No newline at end of file diff --git a/source/docs/models.md b/source/docs/models.md deleted file mode 100644 index 382674e846..0000000000 --- a/source/docs/models.md +++ /dev/null @@ -1,67 +0,0 @@ -title: Models ---- -Hexo uses [Warehouse](https://github.com/tommy351/warehouse) to store everything. You can check the [API](/api/warehouse/classes/Database.html) and see the contents of data model below. - -### Post - -Name | Description ---- | --- -`id` | Post ID (Set by user) -`title` | Post title -`date` | Post date ([Moment.js] object) -`updated` | Post last updated date ([Moment.js] object) -`categories` | All categories of the post -`tags` | All tags of the post -`comments` | Comment enabled or not -`layout` | Layout name -`content` | The full processed content of the post -`excerpt` | The processed excerpt of the post -`source` | The path of the source file -`full_source` | Full path of the source file -`path` | The URL of the post without root URL -`permalink` | Full URL of the post -`raw` | The raw data of the post -`photos` | The photos of the article (Used in gallery posts) -`link` | The external link of the article (Used in link posts) - -### Page - -Name | Description ---- | --- -`title` | Page title -`date` | Page date ([Moment.js] object) -`updated` | Page last updated date ([Moment.js] object) -`comments` | Comment enabled or not -`layout` | Layout name -`content` | The full processed content of the page -`excerpt` | The processed excerpt of the page -`source` | The path of the source file -`full_path` | Full path of the source file -`path` | The URL of the page without root URL -`permalink` | Full URL of the page -`raw` | The raw data of the page - -### Category - -Name | Description ---- | --- -`name` | Category name -`slug` | Category slug -`posts` | All posts in the category -`path` | The URL of the category without root URL -`permalink` | Full URL of the category -`length` | Total number of posts in the category -`parent` | Parent category - -### Tag - -Name | Description ---- | --- -`name` | Tag name -`slug` | Tag slug -`posts` | All posts in the tag -`path` | The URL of the tag without root URL -`permalink` | Full URL of the tag -`length` | Total number of posts in the tag - -[Moment.js]: http://momentjs.com/ \ No newline at end of file diff --git a/source/docs/pagination.md b/source/docs/pagination.md deleted file mode 100644 index b1221f1b86..0000000000 --- a/source/docs/pagination.md +++ /dev/null @@ -1,44 +0,0 @@ -title: Pagination ---- -When there're many posts in your blog, it's useful to separate into several pages. Hexo supports pagination. The following is how you can use pagination in Hexo. - -Before we start, you have to enable pagination. Edit `per_page` setting to change how many posts displayed in a single page. To disable pagination, just set it to `0`. - -``` yaml -per_page: 10 -``` - -You can edit the following setting to enable or disable pagination for specific pages. - -- 2: Enable pagination -- 1: Disable pagination -- 0: Fully disable - -``` yaml -archive: 2 -category: 2 -tag: 2 -``` - -## Basic - -The most basic pagination is just two links: "Previous page" & "Next page". For example: - -``` -<% if (page.prev){ %> - <a href="<%- url_for(page.prev_link) %>">Prev</a> -<% } %> -<% if (page.next){ %> - <a href="<%- url_for(page.next_link) %>">Next</a> -<% } %> -``` - -## Paginator helper - -To display pagination in number. You can use paginator helper. It helps you insert pagination fast. - -``` -<%- paginator() %> -``` - -For more info, see [Helpers](/docs/helpers.html#paginator). diff --git a/source/docs/permalinks.md b/source/docs/permalinks.md index c182365166..ba274c5c9e 100644 --- a/source/docs/permalinks.md +++ b/source/docs/permalinks.md @@ -4,7 +4,7 @@ You can specify the permalinks for your site in `_config.yml` or in the front-ma ### Variables -Besides the following variables, you can use any attributes in the permalink since Hexo 2.5. +Besides the following variables, you can use any attributes in the permalink. Variable | Description --- | --- @@ -15,7 +15,7 @@ Variable | Description `:i_day` | Published day of posts (Without leading zeros) `:title` | Filename `:id` | Post ID -`:category` | Categories. If the post is uncategorized, it'll be `category_dir` setting. +`:category` | Categories. If the post is uncategorized, it'll be `default_category` setting. You can define the default value of each variable in the permalink in `permalink_defaults` setting: diff --git a/source/docs/plugins.md b/source/docs/plugins.md index 2888fa0452..a550990bc3 100644 --- a/source/docs/plugins.md +++ b/source/docs/plugins.md @@ -1,8 +1,6 @@ title: Plugins --- -## Overview - -Hexo has a powerful plugin system. Most of built-in plugins are extensions of Hexo. This makes you easy to hook up your code. +Hexo has a powerful plugin system, which makes you easy to extend functions without modifying source code of the core module. There're two kinds of plugins in Hexo: ### Script @@ -10,7 +8,9 @@ If your code is simple, it's recommended to use a script. All you need to do is ### Plugin -If your code is complicated or you want to publish it to NPM registry, it's recommended to use a plugin. First, create a folder in `node_modules` folder. The name of the folder must be started with `hexo-` so it could be loaded by Hexo. The folder must be contained at least 2 files: One is the main program and the other is `package.json` describing the purpose and the dependencies of the plugin. +If your code is complicated or you want to publish it to NPM registry, it's recommended to use a plugin. First, create a folder in `node_modules` folder. The name of the folder must be started with `hexo-` so it could be loaded by Hexo. + +The folder must be contained at least 2 files: One is the main program and the other is `package.json` describing the purpose and the dependencies of the plugin. ``` plain . @@ -28,433 +28,45 @@ You should at least describe `name`, `version`, `main` in `package.json`. For ex } ``` -### Publishing - -You can publish your plugin to the [plugin list](https://github.com/hexojs/hexo/wiki/Plugins) on wiki. - -## Generator - -Generators are used to generate static files based on processed source files. - -### Syntax - -``` js -hexo.extend.generator.register(name, function(locals, render, callback){ - // ... -}); -``` - -Parameter | Description ---- | --- -`name` | Generator name -`fn` | Generator function - -`fn` is invoked with 3 arguments: - -Argument | Description ---- | --- -`locals` | [Site variables](variables.html) -`render` | Render function -`callback` | Callback function - -### Render Function - -To render contents with templates, use the render function. - -``` js -render(path, layout, locals) -``` - -Argument | Description ---- | --- -`path` | URL without root URL -`layout` | Theme layout to use. This value can be an array or a string. When it's an array, Hexo'll use the first matched layout. -`locals` | Page variables - -If you don't need to render contents with templates. You can bind contents on routes directly: - -``` js -hexo.route.set('feed.xml', content); -``` - -### Example - -``` js -hexo.extend.generator.register(function(locals, render, callback){ - render('archive.html', ['archive', 'index'], locals); - callback(); -}); -``` - -## Renderer - -Renderers are used to render contents. You can find available renderers in [plugin list](https://github.com/hexojs/hexo/wiki/Plugins#renderer). - -### Syntax - -``` js -hexo.extend.renderer.register(name, output, function(data, options, callback){ - // ... -}, sync); -``` - -Parameter | Description ---- | --- -`name` | Input file extension (lowercase, without prefixing `.`) -`output` | Output file extension (lowercase, without prefixing `.`) -`fn` | Render function -`sync` | Sync mode (`false` by default) - -`fn` is invoked with 3 arguments: - -Argument | Description ---- | --- -`data` | `data` contains 2 properties: `path` (File path) and `text` (File content). `path` doesn't always exist in sync mode. -`options` | Options. -`callback` | Callback function. Only used in async mode. - -### Example - -**Sync mode:** - -``` js -var ejs = require('ejs'); - -hexo.extend.renderer.register('ejs', 'html', function(data, options){ - options.filename = data.path; - return ejs.render(data.text, options); -}, true); -``` - -**Async mode:** - -``` js -var stylus = require('stylus'); - -hexo.extend.renderer.register('styl', 'css', function(data, options, callback){ - stylus(data.text).set('filename', data.path).render(callback); -}); -``` - -## Helper - -Helpers are used in templates to help you insert snippets quickly. It's recommended to put complicated or often used code in helpers instead of templates. (Don't repeat yourself, right?) - -### Syntax - -You can get all local variables from `this`. -``` js -hexo.extend.helper.register(name, function(){ - // ... -}); -``` - -Parameter | Description ---- | --- -`name` | Helper name -`fn` | Helper function - -### Example - -``` js -hexo.extend.helper.register('js', function(path){ - return '<script type="text/javascript" src="' + path + '"></script>'; -}); -``` - -``` js -<%- js('script.js') %> -// <script type="text/javascript" src="script.js"></script> -``` - -## Deployer - -Deployer plugin helps you deploy your site on web without complicated commands. - -### Syntax - -``` js -hexo.extend.deployer.register(name, function(args, callback){ - // ... -}); -``` - -Parameter | Description ---- | --- -`name` | Deployer name -`fn` | Deployer function - -`fn` is invoked with 2 arguments: - -Argument | Description ---- | --- -`args` | Deployer options and [Minimist] arguments. -`callback` | Callback function - -## Processor - -Processors are used to process raw data in `source` folder. - -{% note info Hidden files will be ignored %} -Hexo won't process hidden files. -{% endnote %} - -### Syntax - -``` js -hexo.extend.processor.register(rule, function(file, callback){ - // ... -}); -``` - -Paramter | Description ---- | --- -`rule` | File path matching rule. This value can be a [Backbone-style route](http://backbonejs.org/#Router), a regular expression or a function. -`fn` | Processor function - -`fn` is invoked with 2 arguments: - -Argument | Description ---- | --- -`file` | File data (see below) -`callback` | Callback function - -### File data - -You can check [Box.File](/api/classes/Box.File.html) for more info. - -Property | Description ---- | --- -`source` | File source -`path` | File relative path -`type` | File event. The value can be `create`, `update`, `delete` or `skip`. -`read` | Reads the file -`readSync` | Reads the file synchronizedly -`stat` | Gets the file status -`statSync` | Gets the file status synchronizedly -`render` | Renders the file -`renderSync` | Renders the file synchronizedly - -**Reads the file:** - -``` js -file.read([options], callback); -file.readSync([options]); -``` - -Option | Description | Default ---- | --- | --- -`cache` | Enables cache | false -`encoding` | File encoding | utf8 - -**Gets the file status:** - -``` js -file.stat(callback); -file.statSync(); -``` - -**Renders the file:** - -``` js -file.render([options], callback); -file.renderSync([options]); -``` - -## Tag - -Tags are used in posts to help your insert snippets quickly. - -### Syntax - -``` js -hexo.extend.tag.register(name, function(args, content, options){ - // ... -}, options); -``` - -Parameter | Description ---- | --- -`name` | Tag name -`fn` | Tag function -`options` | Options (See below) - -`fn` is invoked with 3 arguments: - -Argument | Description ---- | --- -`args` | Arguments -`content` | Content (Only available when `options.end` is true) -`options` | Swig options - -### Options - -Option | Description | Default ---- | --- | --- -`ends` | Whether a tag must have an end tag | false -`escape` | Escape contents in a tag | true - -### Example - -**Without end tag:** Inserts a Youtube video. - -``` js -hexo.extend.tag.register('youtube', function(args, content, options){ - var id = args[0]; - return '<div class="video-container"><iframe width="560" height="315" src="http://www.youtube.com/embed/' + id + '" frameborder="0" allowfullscreen></iframe></div>'; -}); -``` - -**With end tag:** Inserts a pull quote. - -``` js -hexo.extend.tag.register('pullquote', function(args, content, options){ - var className = args.length ? ' ' + args.join(' ') : ''; - return '<blockquote class="pullquote' + className + '">' + content + '</blockquote>'; -}, true); -``` - -## Console - -Consoles are the interface between Hexo and you. - -### Syntax - -``` js -hexo.extend.console.register(name, desc, options, function(args, callback){ - // ... -}); -``` - -Parameter | Description ---- | --- -`name` | Console name (must be in lowercase) -`desc` | Console description -`options` | Options -`fn` | Console function - -`fn` is invoked with 2 arguments: - -Argument | Description ---- | --- -`args` | [Minimist] arguments -`callback` | Callback function - -### Options - -Option | Description ---- | --- -`init` | Whether the console plugin should display in a non-Hexo folder. -`debug` | Only display in debug mode. -`alias` | The alias for the console plugin. - -### Example - -``` js -hexo.extend.console.register('config', 'Display configuration', function(args, callback){ - console.log(hexo.config); - callback(); -}); -``` - -## Migrator - -Migrators are used to migrate from other system to Hexo. - -### Syntax - -``` js -hexo.extend.migrator.register(name, function(args, callback){ - // ... -}); -``` - -Parameter | Description ---- | --- -`name` | Migrator name -`fn` | Migrator function - -`fn` is invoked with 2 arguments: - -Argument | Description ---- | --- -`args` | [Minimist] arguments -`callback` | Callback function - -## Filter - -Filters are used to modify certain data. Hexo passes data through filters and you can modify everything as long as it's provided. This concept is stolen from [WordPress](http://codex.wordpress.org/Plugin_API#Filters). Filter API is rewritten in 2.6 and more filter types are added. - -### Syntax - -``` js -hexo.extend.filter.register(type, function(){ - // ... -}, priority); -``` - -Parameter | Description ---- | --- -`type` | Filter type (See below) -`fn` | Filter function (Arguments are depend on the filter type) -`priority` | Priority of the filter (Default is 10) - -### Post Filter - -**before_post_render** - -Runs before posts are rendered by Markdown. For example, transform a title into titlecase: - -``` js -hexo.extend.filter.register('before_post_render', function(data, callback){ - data.title = hexo.util.titlecase(data.title); - callback(null, data); -}); -``` - -**after_post_render** - -Runs after posts are rendered by Markdown. For example, replace `@username` to a Twitter profile link. - -``` js -hexo.extend.filter.register('after_post_render', function(data, callback){ - data.content = data.content.replace(/@(\d+)/, '<a href="http://twitter.com/$1">#$1</a>'); - callback(null, data); -}); -``` - -**new_post_path** +### Tools -Runs when creating a post. Used to determine the file path of a post. +You can make use of the official tools provided by Hexo to accelerate development: -``` js -hexo.extend.filter.register('new_post_path', function(data, replace, callback){ - // ... -}); -``` - -**post_permalink** - -Used to determine the permalink of a post. - -``` js -hexo.extend.filter.register('post_permalink', function(data){ - // ... -}); -``` +- [hexo-fs]:File IO +- [hexo-util]:Utilities +- [hexo-i18n]:Localization (i18n) +- [hexo-pagination]:Generate pagination data -**server_middleware** - -Adds a middleware to the server. `app` is an instance of the [Connect] server. - -``` js -hexo.extend.filter.register('server_middleware', function(app){ - app.use(function(req, res, next){ - res.setHeader('X-Powered-By', 'Hexo'); - next(); - }); -}); -``` +### Publishing -[Minimist]: https://github.com/substack/minimist -[Connect]: https://github.com/senchalabs/connect \ No newline at end of file +Once your plugin has been done, you can consider to publish it to [plugin list](/plugins) to make more people use your plugin. The steps to publish a plugin is very simliar to [updating documentation](contributing.html#Updating_Documentation). + +1. Fork [hexojs/site] +2. Clone the repository to your computer and install dependencies. + + {% code %} + $ git clone https://github.com/<username>/site.git + $ cd site + $ npm install + {% endcode %} + +3. Edit `source/_data/_plugins.yml` and add your plugin. For example: + + {% code %} + - name: hexo-server + description: Server module for Hexo. + link: https://github.com/hexojs/hexo-server + tags: + - official + - server + - console + {% endcode %} + +4. Push the branch. +5. Create a pull request and describe the change. + +[hexo-fs]: https://github.com/hexojs/hexo-fs +[hexo-util]: https://github.com/hexojs/hexo-util +[hexo-i18n]: https://github.com/hexojs/hexo-i18n +[hexo-pagination]: https://github.com/hexojs/hexo-pagination +[hexojs/site]: https://github.com/hexojs/site \ No newline at end of file diff --git a/source/docs/server.md b/source/docs/server.md index b423e1cbee..fabdcd7f7f 100644 --- a/source/docs/server.md +++ b/source/docs/server.md @@ -1,24 +1,24 @@ title: Server --- -## Built-in Server +## [hexo-server] -Hexo uses [Connect] as the built-in server. To start server, run the following command: +Server was separated from the main module in Hexo 3. You have to install [hexo-server] before start using. ``` bash -$ hexo server +$ npm install hexo-server --save ``` -Your website will running at `http://localhost:4000`. You can edit the server port in `_config.yml` or use flags to override the default port. For example: +Once the server is installed, run the following command to start the server. Your website will run at `http://localhost:4000` by default. When server is running, Hexo will watch file changes and update automatically. You don't need to restart the server. ``` bash -$ hexo server -p 5000 +$ hexo server ``` -Server will watch for file changes and update automatically. However, server won't update files in `public` folder. You should run `hexo generate` instead. +If you want to modify the port or encounter `EADDRINUSE` error. You can add `-p` option to set other port. -{% note info Restart Hexo after configuration changed %} -Hexo doesn't watch for configuration file changes. You have to restart Hexo to make the new configurations take effects. -{% endnote %} +``` bash +$ hexo server -p 5000 +``` ### Static Mode @@ -30,68 +30,18 @@ $ hexo server -s ### Custom IP -Hexo runs the server at `0.0.0.0` by default. You can override the default IP setting. For example: +Hexo runs the server at `0.0.0.0` by default. You can override the default IP setting. ``` bash $ hexo server -i 192.168.1.1 ``` -### Drafts - -In draft mode, drafts will be served as normal posts. You can preview your drafts on the server. All changes you made on drafts will be updated at once. - -``` bash -$ hexo server -d -``` - -### Logger - -To log requests of server, you can enable logger in `_config.yml`. Logger is always enabled in debug mode. You can check [morgan] for more info. - -``` yaml -logger: true -logger_format: default -``` - -Or use flags to override default settings. For example: - -``` bash -$ hexo server -l default -``` - -**Pre-defined formats:** - -Format | Description ---- | --- -`default` | `:remote-addr - - [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"` -`short` | `:remote-addr - :method :url HTTP/:http-version :status :res[content-length] - :response-time ms` -`tiny` | `:method :url :status :res[content-length] - :response-time ms` -`dev` | concise output colored by response status for development use - -**Tokens:** - -Token | Description ---- | --- -`:req[header]` | Request header (e.g. `:req[Accept]`) -`:res[header]` | Response header (e.g. `:res[Content-Length]`) -`:http-version` | HTTP version -`:response-time` | Response time -`:remote-addr` | Remote IP address -`:date` | Request date -`:method` | Method -`:url` | Request URL -`:referrer` | Referrer -`:user-agent` | User agent -`:status` | Status - ## Pow -[Pow](http://pow.cx/) is a zero-config Rack server for Mac powered by Node.js. +[Pow] is a zero-config Rack server for Mac. ### Install -Run the following command: - ``` bash $ curl get.pow.cx | sh ``` @@ -107,34 +57,5 @@ $ ln -s /path/to/myapp Your website will be up and running at `http://myapp.dev`. The URL is based on the name of symlink. -## Forever / PM2 - -To keep the Hexo server alive, you can use [Forever] or [PM2]. - -Hexo can be run programmatically since 2.5. So you can call Hexo in JavaScript instead of CLI. - -**1. Install Hexo in the folder of your site.** - -``` bash -$ npm install hexo --save -``` - -**2. Add a JavaScript file with the following content.** - -``` js app.js -require('hexo').init({command: 'server'}); -``` - -**3. Run the JavaScript file you just created with [Forever] or [PM2].** - -PM2 has a [known issue](https://github.com/Unitech/pm2#known-bugs-and-workarounds) that the port isn't released when the script is stopped unless PM2 is killed. You have to run the script in fork mode. - -``` bash -$ forever start app.js -$ pm2 start app.js -x -``` - -[Connect]: https://github.com/senchalabs/connect -[morgan]: https://github.com/expressjs/morgan -[Forever]: https://github.com/nodejitsu/forever -[PM2]: https://github.com/Unitech/pm2 \ No newline at end of file +[hexo-server]: https://github.com/hexojs/hexo-server +[Pow]: http://pow.cx/ \ No newline at end of file diff --git a/source/docs/setup.md b/source/docs/setup.md index 01eb826531..7501cb1801 100644 --- a/source/docs/setup.md +++ b/source/docs/setup.md @@ -24,7 +24,7 @@ After build, here's what the project folder looks like: ### _config.yml -Site [configuration](configuration.html) file. You can configure most options here. +Site [configuration](configuration.html) file. You can configure most settings here. ### package.json @@ -33,28 +33,32 @@ Application data. [EJS](http://embeddedjs.com/), [Stylus](http://learnboost.gith ``` json package.json { "name": "hexo-site", - "version": "", + "version": "0.0.0", "private": true, + "hexo": { + "version": "" + }, "dependencies": { - "hexo-generator-archive": "*", - "hexo-generator-category": "*", - "hexo-generator-index": "*", - "hexo-generator-tag": "*", - "hexo-renderer-ejs": "*", + "hexo": "^3.0.0", + "hexo-generator-archive": "^0.1.0", + "hexo-generator-category": "^0.1.0", + "hexo-generator-index": "^0.1.0", + "hexo-generator-tag": "^0.1.0", + "hexo-renderer-ejs": "^0.1.0", "hexo-renderer-stylus": "^0.2.0", - "hexo-renderer-marked": "^0.2.0", - "hexo-server": "*" + "hexo-renderer-marked": "^0.2.4", + "hexo-server": "^0.1.2" } } ``` ### scaffolds -[Scaffold](writing.html) folder. When you create a new post, Hexo will build the file based on the scaffold. +[Scaffold](writing.html#Scaffolds) folder. When you create a new post, Hexo will build the file based on the scaffold. ### scripts -[Script](plugins.html) folder. Scripts are the easiest way to extend Hexo. JavaScript files in this folder will be executed automatically. +[Script](plugins.html#Scripts) folder. Scripts are the easiest way to extend Hexo. JavaScript files in this folder will be executed automatically. ### source @@ -62,4 +66,4 @@ Source folder is where you can put your content. Files or folders whose names ar ### themes -[Theme](themes.html) folder. Hexo will generate files based on the theme. +[Theme](themes.html) folder. Hexo will generate files based on the theme. \ No newline at end of file diff --git a/source/docs/tag-plugins.md b/source/docs/tag-plugins.md index 1125c12204..059937d357 100644 --- a/source/docs/tag-plugins.md +++ b/source/docs/tag-plugins.md @@ -8,23 +8,21 @@ Inserts quotes with author, source and title in posts. **Alias:** quote -{% raw %} -<figure class="highlight"><pre>{% blockquote [author[, source]] [link] [source_link_title] %} +``` +{% blockquote [author[, source]] [link] [source_link_title] %} content {% endblockquote %} -</pre></figure> -{% endraw %} +``` ### Example **No arguments given. Only output plain blockquote** -{% raw %} -<figure class="highlight"><pre>{% blockquote %} +``` +{% blockquote %} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque hendrerit lacus ut purus iaculis feugiat. Sed nec tempor elit, quis aliquam neque. Curabitur sed diam eget dolor fermentum semper at eu lorem. {% endblockquote %} -</pre></figure> -{% endraw %} +``` {% blockquote %} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque hendrerit lacus ut purus iaculis feugiat. Sed nec tempor elit, quis aliquam neque. Curabitur sed diam eget dolor fermentum semper at eu lorem. @@ -32,12 +30,11 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque hendrerit **Quote from a book** -{% raw %} -<figure class="highlight"><pre>{% blockquote David Levithan, Wide Awake %} +``` +{% blockquote David Levithan, Wide Awake %} Do not just seek happiness for yourself. Seek happiness for all. Through kindness. Through mercy. {% endblockquote %} -</pre></figure> -{% endraw %} +``` {% blockquote David Levithan, Wide Awake %} Do not just seek happiness for yourself. Seek happiness for all. Through kindness. Through mercy. @@ -45,12 +42,11 @@ Do not just seek happiness for yourself. Seek happiness for all. Through kindnes **Quote from Twitter** -{% raw %} -<figure class="highlight"><pre>{% blockquote @DevDocs https://twitter.com/devdocs/status/356095192085962752 %} +``` +{% blockquote @DevDocs https://twitter.com/devdocs/status/356095192085962752 %} NEW: DevDocs now comes with syntax highlighting. http://devdocs.io {% endblockquote %} -</pre></figure> -{% endraw %} +``` {% blockquote @DevDocs https://twitter.com/devdocs/status/356095192085962752 %} NEW: DevDocs now comes with syntax highlighting. http://devdocs.io @@ -58,12 +54,11 @@ NEW: DevDocs now comes with syntax highlighting. http://devdocs.io **Quote from an article on the web** -{% raw %} -<figure class="highlight"><pre>{% blockquote Seth Godin http://sethgodin.typepad.com/seths_blog/2009/07/welcome-to-island-marketing.html Welcome to Island Marketing %} +``` +{% blockquote Seth Godin http://sethgodin.typepad.com/seths_blog/2009/07/welcome-to-island-marketing.html Welcome to Island Marketing %} Every interaction is both precious and an opportunity to delight. {% endblockquote %} -</pre></figure> -{% endraw %} +``` {% blockquote Seth Godin http://sethgodin.typepad.com/seths_blog/2009/07/welcome-to-island-marketing.html Welcome to Island Marketing %} Every interaction is both precious and an opportunity to delight. @@ -75,23 +70,21 @@ Inserts code snippets in posts. **Alias:** code -{% raw %} -<figure class="highlight"><pre>{% codeblock [title] [lang:language] [url] [link text] %} +``` +{% codeblock [title] [lang:language] [url] [link text] %} code snippet {% endcodeblock %} -</pre></figure> -{% endraw %} +``` ### Example **A normal code block** -{% raw %} -<figure class="highlight"><pre>{% codeblock %} +``` +{% codeblock %} alert('Hello World!'); {% endcodeblock %} -</pre></figure> -{% endraw %} +``` {% codeblock %} alert('Hello World!'); @@ -99,12 +92,11 @@ alert('Hello World!'); **Specify language** -{% raw %} -<figure class="highlight"><pre>{% codeblock lang:objc %} +``` +{% codeblock lang:objc %} [rectangle setX: 10 y: 10 width: 20 height: 20]; {% endcodeblock %} -</pre></figure> -{% endraw %} +``` {% codeblock lang:objc %} [rectangle setX: 10 y: 10 width: 20 height: 20]; @@ -112,12 +104,11 @@ alert('Hello World!'); **Add caption to code block** -{% raw %} -<figure class="highlight"><pre>{% codeblock Array.map %} +``` +{% codeblock Array.map %} array.map(callback[, thisArg]) {% endcodeblock %} -</pre></figure> -{% endraw %} +``` {% codeblock Array.map %} array.map(callback[, thisArg]) @@ -125,13 +116,12 @@ array.map(callback[, thisArg]) **Add caption with an optional URL** -{% raw %} -<figure class="highlight"><pre>{% codeblock _.compact http://underscorejs.org/#compact Underscore.js %} +``` +{% codeblock _.compact http://underscorejs.org/#compact Underscore.js %} _.compact([0, 1, false, 2, '', 3]); => [1, 2, 3] {% endcodeblock %} -</pre></figure> -{% endraw %} +``` {% codeblock _.compact http://underscorejs.org/#compact Underscore.js %} _.compact([0, 1, false, 2, '', 3]); @@ -152,92 +142,82 @@ code snippet This plugin helps you insert a pull quote in posts. -{% raw %} -<figure class="highlight"><pre>{% pullquote [class] %} +``` +{% pullquote [class] %} content {% endpullquote %} -</pre></figure> -{% endraw %} +``` ## jsFiddle Embeds jsFiddle snippets in posts. -{% raw %} -<figure class="highlight"><pre>{% jsfiddle shorttag [tabs] [skin] [width] [height] %} -</pre></figure> -{% endraw %} +``` +{% jsfiddle shorttag [tabs] [skin] [width] [height] %} +``` ## Gist Embeds Gist snippets in posts. -{% raw %} -<figure class="highlight"><pre>{% gist gist_id [filename] %} -</pre></figure> -{% endraw %} +``` +{% gist gist_id [filename] %} +``` ## iframe Embeds an iframe in posts. -{% raw %} -<figure class="highlight"><pre>{% iframe url [width] [height] %} -</pre></figure> -{% endraw %} +``` +{% iframe url [width] [height] %} +``` ## Image Inserts an image in posts with specified size. -{% raw %} -<figure class="highlight"><pre>{% img [class names] /path/to/image [width] [height] [title text [alt text]] %} -</pre></figure> -{% endraw %} +``` +{% img [class names] /path/to/image [width] [height] [title text [alt text]] %} +``` ## Link Inserts a link with `target="_blank"` attribute. -{% raw %} -<figure class="highlight"><pre>{% link text url [external] [title] %} -</pre></figure> -{% endraw %} +``` +{% link text url [external] [title] %} +``` ## Include Code Inserts code snippets in `source` folder. -{% raw %} -<figure class="highlight"><pre>{% include_code [title] [lang:language] path/to/file %} -</pre></figure> -{% endraw %} +``` +{% include_code [title] [lang:language] path/to/file %} +``` ## Youtube Inserts a Youtube video in posts. -{% raw %} -<figure class="highlight"><pre>{% youtube video_id %} -</pre></figure> -{% endraw %} +``` +{% youtube video_id %} +``` ## Vimeo Inserts a Vimeo video in posts. -{% raw %} -<figure class="highlight"><pre>{% vimeo video_id %} -</pre></figure> -{% endraw %} +``` +{% vimeo video_id %} +``` ## Raw -If there're some contents can't be processed in posts, you can wrapped it with `rawblock` tag. +If there're some contents can't be processed in posts, you can wrapped it with `rawb` tag to avoid rendering errors. +``` {% raw %} -<figure class="highlight"><pre>{% rawblock %} content -{% endrawblock /%} -</pre></figure> -{% endraw %} \ No newline at end of file +{% endraw %} +``` \ No newline at end of file diff --git a/source/docs/themes.md b/source/docs/themes.md index 03f22f51a3..bee88a2e73 100644 --- a/source/docs/themes.md +++ b/source/docs/themes.md @@ -1,6 +1,6 @@ title: Themes --- -## Structure +It's easy to build a Hexo theme. You only have to create a new folder and modify `theme` setting in `_config.yml` and the theme will be changed. A theme may have the following structure: ``` plain . @@ -17,156 +17,62 @@ Theme configuration file. It'll be updated when changed automatically. You don't ### languages -Language folder. Hexo provides a simple i18n module built-in. To enable this feature, edit `language` setting. The language code must be written in [IETF format]. For example: - -``` yaml -language: zh-TW -``` - -A language folder must contain a language file named `default.yml` at least. Language files can be written in YAML or JSON format. - -You can get the localized string in templates from `__` and `_p` helper. The former is for common usage and the letter is for plural strings. You can even use [printf format](https://github.com/alexei/sprintf.js). For example: - -``` yaml default.yml -index: - title: Home - add: Add - video: - zero: No videos - one: One video - other: %d videos -``` - -``` js -<%= __('index.title') %> -// Home - -<%= _p('index.video', 3) %> -// 3 videos -``` +Language folder. See [localization (i18n)](localization.html) for more info. ### layout -Layout folder. File or folder whose name is prefixed with `_` (underscore) and hidden files will be ignored. - -Hexo provides built-in [EJS] and [Swig] template engines. You can install some renderer plugins for [Haml], [Jade] support. Hexo chooses template engines based on the extension name of files. For example: +Layout folder. This folder is used to put template files of the theme. The appearance of your website is depended on templates. Hexo provides built-in [Swig] template engine. You can install plugins for [EJS], [Haml] or [Jade] support. Hexo choose template engines based on the extension name of files. For example: ``` plain EJS: layout.ejs Swig: layout.swig ``` -Every theme should at least contain `index` layout. - -Layout | Description | Fallback ---- | --- | --- -`index` | Index layout | -`post` | Post layout | `index` -`page` | Page layout | `index` -`archive` | Archives layout | `index` -`category` | Category archives layout | `archive` -`tag` | Tag archives layout | `archive` +See [templates](templates.html) for more info. ### scripts -Script folder. JavaScript files in this folder will be loaded when Hexo started. This feature requires Hexo 2.4 and above. - -For more info, see [Plugins](plugins.html). +Script folder. JavaScript files in this folder will be loaded when Hexo started. For more info, see [Plugins](plugins.html). ### source Source folder. Asset files like CSS and Javascript files should be placed in this folder. File or folder whose name is prefixed with `_` (underscore) and hidden files will be ignored. -Files which are able to rendered by renderer plugins will be rendered, such as Stylus files. Hexo provides built-in [Stylus] renderer plugin (with [nib] support). You can install some renderer plugins for [Less], [CoffeeScript] support. - -{% note info Get config in Stylus File %} -You can get global and theme configuration by using `hexo-config(key)` in stylus file. -{% endnote %} - -## Layout - -Layout wraps a template to another layout template. A layout must contain `<%- body %>` so that it can show the contents of the template. For example: - -``` html index.ejs -index -``` - -``` html layout.ejs -<!DOCTYPE html> -<html> - <body><%- body %></body> -</html> -``` - -yields: - -``` html -<!DOCTYPE html> -<html> - <body>index</body> -</html> -``` - -By default, every template file uses `layout.ejs` as the layout. You can specify other layouts in front-matter or use `false` to disable the layout. You can also use a layout in another layout to create nested layouts. - -## Partial - -Partial helps you share components across templates. For example: - -``` html _partial/header.ejs -<header></header> -``` - -``` html index.ejs -<%- partial('_partial/header') %> -<div id="content"></div> -``` - -yields: - -``` -<header></header> -<div id="content"></div> -``` - -You can pass data to partials by defining local variables: - -``` js -<%- partial('_partial/header', {title: 'Hello World'}) %> -``` - -For more info, see [partial helper](helpers.html#partial). - -## Optimization - -If your theme is too complicated and too may source files needed to be generate. Generation performance may decrease a lot. Besides simplifying your theme, you can also try **Fragment Caching** introduced in Hexo 2.7. - -This feature is stolen from [Ruby on Rails](http://guides.rubyonrails.org/caching_with_rails.html#fragment-caching). It saves the contents within a fragment and serves the cache when the next request comes in. It can reduce database queries and make generation faster. - -It can be used in header, footer, sidebar or static contents that won't be changed in your templates. For example: - -``` js -<%- fragment_cache('header', function(){ - return '<header></header>'; -}); -``` - -It would be easier if you use partial: - -``` js -<%- partial('header', {}, {cache: true}); -``` - -## Publishing - -You can publish your theme to the [theme list](https://github.com/hexojs/hexo/wiki/Themes) on wiki. Before publishing, you should test it with [Theme Unit Test](https://github.com/hexojs/hexo-theme-unit-test). - -[IETF format]: http://www.w3.org/International/articles/language-tags/ -[EJS]: https://github.com/visionmedia/ejs +If a file is able to be rendered, then it will be processed and save to `public` folder, or it would be copy to `public` folder directly. + +### Publishing + +Once your theme has been done, you can consider to publish it to [theme list](/themes) to make more people use your theme. It's recommended to run the [theme unit test](https://github.com/hexojs/hexo-theme-unit-test) and ensure everything is working before you publishing. The steps to publish a theme is very simliar to [updating documentation](contributing.html#Updating_Documentation). + +1. Fork [hexojs/site] +2. Clone the repository to your computer and install dependencies. + + {% code %} + $ git clone https://github.com/<username>/site.git + $ cd site + $ npm install + {% endcode %} + +3. Edit `source/_data/_plugins.yml` and add your theme. For example: + + {% code %} + - name: landscape + description: A brand new default theme for Hexo. + link: https://github.com/hexojs/hexo-theme-landscape + preview: http://hexo.io/hexo-theme-landscape + tags: + - official + - responsive + - widget + - two_column + - one_column + {% endcode %} + +4. Add a screenshot in `source/themes/screenshots` with same name. The picture must be 800X500 px and PNG format. +5. Push the branch. +6. Create a pull request and describe the change. + +[EJS]: https://github.com/hexojs/hexo-renderer-ejs [Swig]: http://paularmstrong.github.com/swig/ [Haml]: https://github.com/hexojs/hexo-renderer-haml -[Jade]: https://github.com/hexojs/hexo-renderer-jade -[Stylus]: http://learnboost.github.com/stylus/ -[nib]: http://visionmedia.github.com/nib/ -[Less]: https://github.com/hexojs/hexo-renderer-less -[CoffeeScript]: https://github.com/hexojs/hexo-renderer-coffeescript \ No newline at end of file +[Jade]: https://github.com/hexojs/hexo-renderer-jade \ No newline at end of file diff --git a/source/docs/troubleshooting.md b/source/docs/troubleshooting.md index 3b41d3dd54..e0665d4c69 100644 --- a/source/docs/troubleshooting.md +++ b/source/docs/troubleshooting.md @@ -5,20 +5,21 @@ You may encounter some problems when using Hexo. The following are the solutions ## YAML Parsing Error ``` plain -/usr/local/lib/node_modules/hexo/node_modules/yamljs/bin/yaml.js:1219 -throw new YamlParseException('Unable to parse.', this.getRealCurrentLineNb -^ -YamlParseException: Unable to parse. +JS-YAML: incomplete explicit mapping pair; a key node is missed at line 18, column 29: + last_updated: Last updated: %s ``` -When you encounter `YamlParseException`, check your configuration and front-matter in the post files. Make sure they are written in correct YAML format: use spaces instead of tabs and add a space before colons. For example: +Wrap the string with quotations if it contains colons. -``` yaml -foo: 1 -bar: - baz: 2 +``` plain +JS-YAML: bad indentation of a mapping entry at line 18, column 31: + last_updated:"Last updated: %s" ``` +Make sure you are using soft tab and add a space after colons. + +You can see [YAML Spec](http://www.yaml.org/spec/1.2/spec.html) for more info. + ## EMFILE Error ``` plain @@ -31,13 +32,13 @@ Though Node.js has non-blocking I/O, the number of synchronous I/O is still limi $ ulimit -n 10000 ``` -## GitHub Deployment Problems +## Git Deployment Problems ``` plain fatal: 'username.github.io' does not appear to be a git repository ``` -Make sure you have [set up git](https://help.github.com/articles/set-up-git) on your computer and try to use HTTPS repository URL instead. +Make sure you have [set up git](https://help.github.com/articles/set-up-git) on your computer or try to use HTTPS repository URL instead. ## Server Problems @@ -45,7 +46,7 @@ Make sure you have [set up git](https://help.github.com/articles/set-up-git) on Error: listen EADDRINUSE ``` -You may open Hexo server twice or there's other applications using the same port. Try to edit `port` setting or start Hexo server with `-p` flag. +You may have started two Hexo server at the same time or there's another application using the same port. Try to edit `port` setting or start Hexo server with `-p` flag. ``` bash $ hexo server -p 5000 @@ -53,12 +54,6 @@ $ hexo server -p 5000 ## Plugin Installation Problems -``` plain -npm WARN package.json plugin-name@0.0.1 No read me data. -``` - -This error comes out when you install a plugin which doesn't provide read me file. Don't be scared. This error won't cause any problems. - ``` plain npm ERR! node-waf configure build ``` @@ -67,19 +62,31 @@ This error may occurred when you trying to install a plugin written in C, C++ or ## Iterate Data Model on Jade or Swig -Hexo uses [Warehouse] as data model. It's not an array so you have to transform them into to iterate. For more information about [Warehouse], see the [API](/api/warehouse/classes/Database.html). +Hexo uses [Warehouse] as data model. It's not an array so you have to transform them into to iterate. -## Stylesheets Not Updated +``` +{% for post in site.posts.toArray() %} +{% endfor %} +``` + +## Data Not Updated -You may find that stylesheets updated in Hexo server but not applied to static files. It's because Hexo compares modified date of files when generating. You can clean cache to solve this problem. +Some data may not be updated, or generated files are same to the last version. You can clean the cache and try again. ``` bash $ hexo clean ``` -## Escape in Posts +## Escape Contents -Hexo uses [Swig] to render posts. Contents wrapped with `{% raw %}{{ }}{% endraw %}` or `{% raw %}{% %}{% endraw %}` will be parsed and may cause problems. You can wrap sensitive contents with `raw` tag plugin. +Hexo uses [Nunjucks] to render posts (used [Swig] in old version, they shared a simliar syntax). Contents wrapped with `{% raw %}{{ }}{% endraw %}` or `{% raw %}{% %}{% endraw %}` will be parsed and may cause problems. You can wrap sensitive contents with `raw` tag plugin. + +``` +{% raw %} +Hello {{ sensitive }} +{% endraw %} +``` [Warehouse]: https://github.com/tommy351/warehouse -[Swig]: http://paularmstrong.github.io/swig/ \ No newline at end of file +[Swig]: http://paularmstrong.github.io/swig/ +[Nunjucks]: http://mozilla.github.io/nunjucks/ \ No newline at end of file diff --git a/source/docs/variables.md b/source/docs/variables.md index 129cc7e348..3d671f33ee 100644 --- a/source/docs/variables.md +++ b/source/docs/variables.md @@ -9,18 +9,12 @@ Variable | Description `config` | Site configuration `theme` | Theme configuration. Inherits from site configuration. `_` (single underscore) | [Lodash](http://lodash.com/) library -`__` (double underscores) | Internationalization (i18n) utility. See below for detail. `path` | Path of current page `url` | Full URL of current page - -{% note tip Custom Variables %} -You can also use front-matter in layouts just like writing posts! -{% endnote %} +`env` | Environment variables ### Site Variables -All of the following variables are [Data Model]. - Variable | Description --- | --- `site.posts` | All posts @@ -42,7 +36,8 @@ Variable | Description `page.comments` | Comment enabled or not `page.layout` | Layout name. `page.content` | The full processed content of the article -`page.excerpt` | The processed excerpt of the article +`page.excerpt` | Article excerpt +`page.more` | Contents except article excerpt `page.source` | The path of the source file `page.full_source` | Full path of the source file `page.path` | The URL of the article without root URL. We usually use `url_for(page.path)` in theme. @@ -53,10 +48,6 @@ Variable | Description `page.photos` | The photos of the article (Used in gallery posts) `page.link` | The external link of the article (Used in link posts) -{% note info Custom front-matter %} -The front-matter in posts will be available in `page`. -{% endnote %} - **Home (index)** Variable | Description diff --git a/source/docs/writing.md b/source/docs/writing.md index 79841bfba4..b242a259cb 100644 --- a/source/docs/writing.md +++ b/source/docs/writing.md @@ -1,39 +1,30 @@ title: Writing --- -## Create a New Post - -You can create a new post by yourself or run the following command. If `layout` isn't defined, it'll be the `default_layout` setting. If there're spaces or other special characters in `title`, wrap it with quotation marks. +We're going to create the very first new post in the blog. You can modify the existing post "Hello World". But we recommended you to learn the `new` command. ``` bash $ hexo new [layout] <title> ``` +You can set the layout of specified posts. It's `post` by default. You can modify `default_layout` in `_config.yml` to change the default layout. + ### Layout -Hexo has 2 default layouts: `post` and `page`. Other layouts will be saved in `source/_posts` by default. +There're three default layouts in Hexo: `post`, `page` and `draft`. Each of them has different paths. Other customized layouts is same to `post`. They will be saved to `source/_posts` folder. -Layout | Destination +Layout | Path --- | --- -`post` (Default) | source/_posts -`page` | source +`post` | `source/_posts` +`page` | `source` +`draft` | `source/_drafts` {% note tip Don't process my posts! %} If you don't want your posts processed, you can set `layout: false` in front-matter. {% endnote %} -### Example - -``` bash -$ hexo new "New Post" -# => The file will be created at source/_posts/new-post.md - -$ hexo new page "New Page" -# => The file will be created at source/new-page/index.html -``` - ### Filename -You can modify the name of files created by Hexo in `new_post_name` setting. +Hexo uses the title as file name by default. You can edit `new_post_name` setting to change the default file name. For example, set to `:year-:month-:day-:title.md` can make you more convenient to manage posts. Variable | Description --- | --- @@ -44,120 +35,28 @@ Variable | Description `:day` | Created day (2-digit) `:i_day` | Created day (Without leading zeros) -{% note tip Organize your posts by date %} -You can set `new_post_name` as `:year-:month-:day-:title.md` to make your posts ordered by date. -{% endnote %} - -## Front-matter - -Front-matter is a block wrapped with `---` in front of the file. For example: - -``` yaml -title: Hello World -date: 2013/7/13 20:46:25 ---- -``` - -You can configure all post configuration in the front-matter. The following is predefined settings. - -Setting | Description | Default ---- | --- | --- -`layout` | Layout | post/page -`title` | Title | -`date` | Published date | File created date -`updated` | Last updated date | File last updated date -`comments` | Enables comment feature for the post | true -`tags` | Tags (Not available for pages) | -`categories` | Categories (Not available for pages) | -`permalink` | Overrides the default permalink of the post | Filename - -{% note warn YAML front-matter %} -Write the front-matter in YAML format. Don't use tabs in the front-matter, use spaces instead. Also, add a space after colons. -{% endnote %} - -## Categories & Tags - -Hexo supports categories and tags. Categories and tags are only supported in posts and have to be set in the front-matter. For example: - -``` yaml -categories: -- Diary -tags: -- PS3 -- Games -``` - -Categories and tags may sound familiar in other systems, but they're totally different in Hexo. Categories are hierarchical and ordered, which means `Foo, Bar` doesn't equal to `Bar, Foo`. Tags are unordered and flat. - -## Excerpts +### Drafts -You can hide parts of your post by adding `<!-- more -->` in the content. Index page will only show the post from the first to the second occurrence of `<!-- more -->`. +Previously we mentioned a special layout in Hexo: `draft`. This layout will be saved to `source/_drafts` folder. You can use `publish` command to move drafts to `source/_posts` folder. The usage of this command is very simliar to `new` command. You can also set `layout` in the command to specify layout. -``` markdown -... - -<!-- more --> - -... -``` - -## Code Highlighting - -There're 2 ways for you to highlight your code snippets in your posts: **Backtick code block** and **Swig code block**. Both are ported from Octopress. - -### Backtick Code Block - -{% code %} -``` [language] [title] [url] [link text] -code snippet +``` bash +$ hexo publish [layout] <title> ``` -{% endcode %} -### Swig Code Block +Drafts are not displayed by default. You can add `--draft` option when running Hexo or enable `render_drafts` setting to preview drafts. -{% raw %} -<figure class="highlight"><pre>{% code [title] [lang:language] [url] [link text] %} -code snippet -{% endcode %} -</pre></figure> -{% endraw %} +### Scaffolds -## Scaffold - -Hexo will create a new post based on the correspond scaffold. For example: +When creating posts, Hexo will build files based on the corresponding file in `scaffolds` folder. For example: ``` bash $ hexo new photo "My Gallery" -# => The file will be created at source/_posts/my-gallery.md -``` - -Hexo will find the scaffold file named `photo` in the `scaffolds` folder. If the scaffold not exists, use the post scaffold instead. - -### Example - -Variables are wrapped by double curly brackets. For example: - -``` plain -layout: {% raw %}{{ layout }}{% endraw %} -title: {% raw %}{{ title }}{% endraw %} -date: {% raw %}{{ date }}{% endraw %} ---- ``` -### Variables +When you running this command, Hexo will try to find `photo.md` in `scaffolds` folder and build the post based on it. The following is the available variables in scaffolds: Variable | Description --- | --- -`layout` | Layout name -`title` | Post title -`date` | File created date - -## Asset Folder - -If you put all images and other assets in `source` folder. You can try to enable `post_asset_folder` setting. - -``` yaml -post_asset_folder: true -``` - -After enabling this setting, a folder will be created when you create a new post. This folder is for you to put all asset files used in the post in. It would be much easier to use a image in a post. +`layout` | Layout +`title` | Title +`date` | File created date \ No newline at end of file diff --git a/source/zh-cn/docs/index.md b/source/zh-cn/docs/index.md index 68be06d32c..6cad0724ce 100644 --- a/source/zh-cn/docs/index.md +++ b/source/zh-cn/docs/index.md @@ -21,7 +21,7 @@ Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 [Markdown](h 如果您的电脑中已经安装上述必备程序,那么恭喜您!接下来只需要使用 npm 即可完成 Hexo 的安装。 ``` bash -$ npm install -g hexo +$ npm install -g hexo-cli ``` 如果您的电脑中尚未安装所需要的程序,请根据以下安装指示完成安装。 @@ -66,5 +66,5 @@ $ nvm install 0.10 所有必备的应用程序安装完成后,即可使用 npm 安装 Hexo。 ``` bash -$ npm install -g hexo +$ npm install -g hexo-cli ``` diff --git a/source/zh-tw/api/box.md b/source/zh-tw/api/box.md new file mode 100644 index 0000000000..11aeefc876 --- /dev/null +++ b/source/zh-tw/api/box.md @@ -0,0 +1,4 @@ +title: 箱子(Box) +--- +「箱子」是 Hexo 用來處理特定資料夾中的檔案的容器,在 Hexo 中有兩個箱子,分別是 `hexo.source` 和 `hexo.theme`,前者用於處理 `source` 資料夾,而後者用於處理主題資料夾。 + diff --git a/source/zh-tw/api/events.md b/source/zh-tw/api/events.md new file mode 100644 index 0000000000..6a6f949b75 --- /dev/null +++ b/source/zh-tw/api/events.md @@ -0,0 +1,52 @@ +title: 事件 +--- +Hexo 繼承了 [EventEmitter],您可用 `on` 方法監聽 Hexo 所發佈的事件,亦可用 `emit` 方法對 Hexo 發佈事件,更詳細的說明請參閱 Node.js 的 API。 + +### deployBefore + +在佈署工作執行前發佈。 + +### deployAfter + +在佈署工作執行成功後發佈。 + +### exit + +在 Hexo 結束前發佈。 + +### generateBefore + +在產生靜態檔案前發佈。 + +### generateAfter + +在靜態檔案產生完成後發佈。 + +### new + +在文章檔案建立完成後發佈。此事件會回傳資料參數。 + +``` js +hexo.on('new', function(post){ + // +}); +``` + +資料 | 描述 +--- | --- +`post.path` | 文章檔案的完整路徑 +`post.content` | 文章檔案的內容 + +### processBefore + +在處理原始檔案前發佈。此事件會回傳一個路徑,代表箱子(Box)的根目錄。 + +### processAfter + +在原始檔案處理完成後發佈。此事件會回傳一個路徑,代表箱子(Box)的根目錄。 + +### ready + +在初始化完成後發佈。 + +[EventEmitter]: http://nodejs.org/api/events.html \ No newline at end of file diff --git a/source/zh-tw/api/index.md b/source/zh-tw/api/index.md index 7a95c9d912..bd3170506b 100644 --- a/source/zh-tw/api/index.md +++ b/source/zh-tw/api/index.md @@ -1,3 +1,63 @@ title: API --- -本文件提供您更豐富的 API 資訊,使您更容易修改 Hexo 原始碼或撰寫外掛。如果您只是想要查詢關於 Hexo 的基本使用方法,請參閱 [文件](../docs/)。 \ No newline at end of file +本文件提供您更豐富的 API 資訊,使您更容易修改 Hexo 原始碼或撰寫外掛。如果您只是想要查詢關於 Hexo 的基本使用方法,請參閱 [文件](../docs/)。 + +在開始之前,請注意本文件僅適用於 Hexo 3 及以上版本。 + +## 初始化 + +首先,我們必須建立一個 Hexo 實例(instance),第一個參數是網站的根目錄,也就是 `base_dir`,而第二個參數則是初始化的選項。接著執行 `init` 方法後,Hexo 會載入外掛及配置檔案。 + +``` js +var Hexo = require('hexo'); +var hexo = new Hexo(process.cwd(), {}); + +hexo.init().then(function(){ + // ... +}); +``` + +選項 | 描述 | 預設值 +--- | --- | --- +`debug` | 開啟除錯模式。在終端機中顯示除錯訊息,並在根目錄中儲存 `debug.log` 記錄檔。| `false` +`safe` | 開啟安全模式。不要載入任何外掛。| `false` +`silent` | 開啟安靜模式。不要在終端機中顯示任何訊息。| `false` +`config` | 指定配置檔案的路徑。| `_config.yml` + +## 載入檔案 + +Hexo 提供了兩種方法來載入檔案:`load`, `watch`,前者用於載入 `source` 資料夾內的所有檔案及主題資料;而後者除了執行 `load` 以外,還會繼續監看檔案變動。 + +這兩個方法實際上所做的,就是載入檔案列表,並把檔案傳給相對應的處理器(Processor),當檔案全部處理完畢後,就執行產生器(Generator)來建立路由。 + +``` js +hexo.load().then(function(){ + // ... +}); + +hexo.watch().then(function(){ + // 之後可呼叫 hexo.unwatch() 停止檔案監看 +}); +``` + +## 執行指令 + +您可透過 `call` 方法來呼叫控制台(Console),第一個參數是控制台的名稱,而第二個參數是選項,根據不同控制台而有所不同。 + +``` js +hexo.call('generate', {}).then(function(){ + // ... +}); +``` + +## 結束 + +當指令完畢後,請執行 `exit` 方法讓 Hexo 完成結束前的準備工作(如儲存資料庫)。 + +``` js +hexo.call('generate').then(function(){ + return hexo.exit(); +}).catch(function(err){ + return hexo.exit(err); +}); +``` \ No newline at end of file diff --git a/source/zh-tw/api/locals.md b/source/zh-tw/api/locals.md new file mode 100644 index 0000000000..2d7f50a6bf --- /dev/null +++ b/source/zh-tw/api/locals.md @@ -0,0 +1,44 @@ +title: 區域變數 +--- +區域變數用於模版渲染,也就是模版中的 `site` 變數。 + +## 預設變數 + +變數 | 描述 +--- | --- +`posts` | 所有文章 +`pages` | 所有分頁 +`categories` | 所有分類 +`tags` | 所有標籤 + +## 取得變數 + +``` js +hexo.locals.get('posts') +``` + +## 設定變數 + +``` js +hexo.locals.set('posts', function(){ + return ... +}); +``` + +## 移除變數 + +``` js +hexo.locals.remove('posts'); +``` + +## 取得所有變數 + +``` js +hexo.locals.toObject(); +``` + +## 清除快取 + +``` js +hexo.locals.invalidate(); +``` \ No newline at end of file diff --git a/source/zh-tw/api/router.md b/source/zh-tw/api/router.md new file mode 100644 index 0000000000..a1ac58cabe --- /dev/null +++ b/source/zh-tw/api/router.md @@ -0,0 +1,73 @@ +title: 路由 +--- +路由儲存了網站中所用到的所有路徑。 + +## 取得路徑 + +`get` 方法會傳回一個 [Stream],例如把該路徑的資料儲存到某個指定位置。 + +``` js +var data = hexo.route.get('index.html'); +var dest = fs.createWriteStream('somewhere'); + +data.pipe(dest); +``` + +## 設定路徑 + +您可在 `set` 方法中使用字串、[Buffer] 或函數,如下: + +``` js +// String +hexo.route.set('index.html', 'index') + +// Buffer +hexo.route.set('index.html', new Buffer('index')); + +// Function (Promise) +hexo.route.set('index.html', function(){ + return new Promise(function(resolve, reject){ + resolve('index'); + }); +}); + +// Function (Callback) +hexo.route.set('index.html', function(callback){ + callback(null, 'index'); +}); +``` + +您還可設定該路徑是否更新,這樣在生成檔案時便能忽略未更動的檔案,加快生成時間。 + +``` js +hexo.route.set('index.html', { + data: 'index', + modified: false +}); + +// hexo.route.isModified('index.html') => false +``` + +## 移除路徑 + +``` js +hexo.route.remove('index.html'); +``` + +## 取得路由表 + +``` js +hexo.route.list(); +``` + +## 格式化路徑 + +`format` 方法可將字串轉為合法的路徑。 + +``` js +hexo.route.format('archives/'); +// archives/index.html +``` + +[Stream]: http://nodejs.org/api/stream.html +[Buffer]: http://nodejs.org/api/buffer.html \ No newline at end of file diff --git a/source/zh-tw/docs/asset-folders.md b/source/zh-tw/docs/asset-folders.md index 942fd322cf..c1732b7d0f 100644 --- a/source/zh-tw/docs/asset-folders.md +++ b/source/zh-tw/docs/asset-folders.md @@ -10,11 +10,10 @@ post_asset_folder: true ## 標籤外掛 -Hexo 3.0 新增了幾個外掛,讓您更方便的在文章內引用資產。 +Hexo 3 新增了幾個外掛,讓您更方便的在文章內引用資產。 -{% raw %} -<figure class="highlight"><pre>{% asset_path slug %} +``` +{% asset_path slug %} {% asset_img slug %} {% asset_link slug [title] %} -</pre></figure> -{% endraw %} \ No newline at end of file +``` \ No newline at end of file diff --git a/source/zh-tw/docs/commands.md b/source/zh-tw/docs/commands.md index f88505ff54..bb53df6b4b 100644 --- a/source/zh-tw/docs/commands.md +++ b/source/zh-tw/docs/commands.md @@ -147,4 +147,12 @@ $ hexo --config custom.yml $ hexo --draft ``` -顯示 `source/_drafts` 資料夾中的草稿文章。 \ No newline at end of file +顯示 `source/_drafts` 資料夾中的草稿文章。 + +### 自定 CWD + +``` bash +$ hexo --cwd /path/to/cwd +``` + +自定目前工作目錄(Current working directory)的路徑。 \ No newline at end of file diff --git a/source/zh-tw/docs/configuration.md b/source/zh-tw/docs/configuration.md index 331e976fa0..0657965f4a 100644 --- a/source/zh-tw/docs/configuration.md +++ b/source/zh-tw/docs/configuration.md @@ -2,7 +2,7 @@ title: 配置 --- 您可以在 `_config.yml` 中修改大部份的配置。 -## 網站 +### 網站 設定 | 描述 --- | --- @@ -13,7 +13,7 @@ title: 配置 `language` | 網站使用的語言 `timezone` | 網站時區。Hexo 預設使用您電腦的時區。[時區列表](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) -## 網址 +### 網址 設定 | 描述 | 預設值 --- | --- | --- @@ -26,7 +26,7 @@ title: 配置 如果您的網站存放在子目錄中,例如 `http://yoursite.com/blog`,則請將您的 `url` 設為 `http://yoursite.com/blog` 並把 `root` 設為 `/blog/`。 {% endnote %} -## 目錄 +### 目錄 設定 | 描述 | 預設值 --- | --- | --- @@ -39,7 +39,7 @@ title: 配置 `i18n_dir` | 國際化(i18n)資料夾 | :lang `skip_render` | 跳過指定檔案的渲染,您可使用 glob 來配對路徑。 | -## 寫作 +### 寫作 設定 | 描述 | 預設值 --- | --- | --- @@ -55,7 +55,7 @@ title: 配置 `future` | 顯示未來的文章 | true `highlight` | 程式碼區塊的設定 | -## 分類 & 標籤 +### 分類 & 標籤 設定 | 描述 | 預設值 --- | --- | --- @@ -63,7 +63,7 @@ title: 配置 `category_map` | 分類別名 | `tag_map` | 標籤別名 | -## 日期 / 時間格式 +### 日期 / 時間格式 Hexo 使用 [Moment.js](http://momentjs.com/) 來解析和顯示時間。 @@ -72,14 +72,14 @@ Hexo 使用 [Moment.js](http://momentjs.com/) 來解析和顯示時間。 `date_format` | 日期格式 | MMM D YYYY `time_format` | 時間格式 | H:mm:ss -## 分頁 +### 分頁 設定 | 描述 | 預設值 --- | --- | --- `per_page` | 一頁顯示的文章量 (0 = 關閉分頁功能) | 10 `pagination_dir` | 分頁目錄 | page -## 擴充套件 +### 擴充套件 設定 | 描述 --- | --- diff --git a/source/zh-tw/docs/contributing.md b/source/zh-tw/docs/contributing.md index 4467a1d333..65684bd79b 100644 --- a/source/zh-tw/docs/contributing.md +++ b/source/zh-tw/docs/contributing.md @@ -37,7 +37,7 @@ title: 貢獻 $ git push origin new_feature {% endcode %} -6. 對 `master` 分支建立一個新的合併申請(pull request)並描述變更。 +6. 建立一個新的合併申請(pull request)並描述變更。 ### 注意事項 @@ -50,7 +50,9 @@ title: 貢獻 ## 更新文件 -Hexo 文件開放原始碼,您可以在 [hexojs/site] 找到原始碼,若要修改文件: +Hexo 文件開放原始碼,您可以在 [hexojs/site] 找到原始碼。 + +### 工作流程 1. Fork [hexojs/site] 2. 把檔案庫(repository)複製到電腦上,並安裝相依套件。 @@ -68,11 +70,9 @@ Hexo 文件開放原始碼,您可以在 [hexojs/site] 找到原始碼,若要 {% endcode %} 4. 推送(push)分支。 -5. 對 `master` 分支建立一個新的合併申請(pull request)並描述變更。 +5. 建立一個新的合併申請(pull request)並描述變更。 -## 翻譯文件 - -翻譯文件的流程與上述的文件更新非常相似,如果要新增語言的話,請遵照以下步驟: +### 翻譯 1. 在 `source` 資料夾中建立一個新的語言資料夾(全小寫)。 2. 把 `source` 資料夾中相關的檔案(Markdown 和模板檔案)複製到新的語言資料夾中。 @@ -84,12 +84,7 @@ Hexo 文件開放原始碼,您可以在 [hexojs/site] 找到原始碼,若要 當您在使用 Hexo 時遭遇問題,您可試著在 [解決問題](=troubleshooting.html) 中尋找解答,或是在 [GitHub](https://github.com/hexojs/hexo/issues) 或 [Google Group](https://groups.google.com/group/hexo) 詢問。詢問時請務必附上以下資訊: 1. 以 [除錯模式](commands.html#除錯模式) 再執行一次。 -2. 檢查版本資訊。 - - {% code %} - $ hexo version - {% endcode %} - +2. 執行 `hexo vesion` 並檢查版本資訊。 3. 把除錯資訊和版本資訊都貼到 GitHub。 [hexojs/hexo]: https://github.com/hexojs/hexo diff --git a/source/zh-tw/docs/data-files.md b/source/zh-tw/docs/data-files.md index 935ba7a481..242b522903 100644 --- a/source/zh-tw/docs/data-files.md +++ b/source/zh-tw/docs/data-files.md @@ -1,6 +1,6 @@ title: 資料檔案 --- -有時您可能需要在主題中使用某些資料,而這些資料並不在文章內,或是可以重複使用,那麼您可以考慮使用 Hexo 3.0 新增的「資料檔案」功能。此功能會載入 `source/_data` 內的 YAML 或 JSON 檔案,如此一來您便能在網站中使用。 +有時您可能需要在主題中使用某些資料,而這些資料並不在文章內,或是想要重複使用,那麼您可以考慮使用 Hexo 3 新增的「資料檔案」功能。此功能會載入 `source/_data` 內的 YAML 或 JSON 檔案,如此一來您便能在網站中使用。 舉例來說,在 `source/_data` 資料夾中新增 `menu.yml` 檔案: diff --git a/source/zh-tw/docs/drafts.md b/source/zh-tw/docs/drafts.md deleted file mode 100644 index 7c7a5fe20d..0000000000 --- a/source/zh-tw/docs/drafts.md +++ /dev/null @@ -1,35 +0,0 @@ -title: Drafts ---- -## Creating - -You can create a draft by using `hexo new` command. For example: - -``` bash -$ hexo new draft <title> -``` - -Files will be saved in `source/_drafts` folder. - -## Previewing - -To preview your site with drafts, you can enable `render_drafts` setting in `_config.yml`: - -``` yaml -render_drafts: true -``` - -or run `hexo server` with `-d` or `--drafts` flag. - -``` bash -$ hexo server --drafts -``` - -## Publishing - -Once your draft is done, you can publish it with `hexo publish` command. - -``` bash -$ hexo publish [layout] <filename> -``` - -Files will be moved to `source/_posts` folder and applied with the layout you specified in the command. \ No newline at end of file diff --git a/source/zh-tw/docs/events.md b/source/zh-tw/docs/events.md deleted file mode 100644 index d990f81f64..0000000000 --- a/source/zh-tw/docs/events.md +++ /dev/null @@ -1,66 +0,0 @@ -title: Events ---- -## Overview - -Hexo inherits EventEmitter of Node.js. You can subscribe or publish specified events. For example: - -``` js -hexo.on('ready', function(){ - console.log('Hexo is ready to go!'); -}); -``` - -## Events - -### ready - -Called once Hexo is initialized. - -### generateBefore - -Called before generating. - -### generateAfter - -Called after generating. - -### processBefore - -Called before processing. - -Argument | Description ---- | --- -`path` | Base path of the processor - -### processAfter - -Called after processing. - -Argument | Description ---- | --- -`path` | Base path of the processor - -### new - -Called after a new post file is created. - -Argument | Description ---- | --- -`path` | Absolute path of the post file -`content` | Content of the post file - -### server - -Called after server is on. - -### exit - -Called when Hexo exits. - -### deployBefore - -Called before deployment. - -### deployAfter - -Called after deployment. \ No newline at end of file diff --git a/source/zh-tw/docs/front-matter.md b/source/zh-tw/docs/front-matter.md index a6fdce4e9c..154f54b348 100644 --- a/source/zh-tw/docs/front-matter.md +++ b/source/zh-tw/docs/front-matter.md @@ -21,7 +21,7 @@ date: 2013/7/13 20:46:25 `categories` | 分類(不適用於分頁)| `permalink` | 覆蓋文章網址 | -## 分類和標籤 +### 分類和標籤 分類和標籤只有文章才支援,您可以在 Front-matter 中設定。在其他系統中,分類和標籤可能聽起來很接近,但是在 Hexo 中有著決定性的差別:分類是有順序和階層性的,也就是說 `Foo, Bar` 不等於 `Bar, Foo`;而標籤沒有順序和階層。 @@ -33,7 +33,7 @@ tags: - Games ``` -## JSON Front-matter +### JSON Front-matter 除了 YAML 外,你也可利用 JSON 來撰寫 Front-matter,只要將 `---` 代換成 `;;;` 即可。 diff --git a/source/zh-tw/docs/helpers.md b/source/zh-tw/docs/helpers.md index 7454e19d3b..54b8a61934 100644 --- a/source/zh-tw/docs/helpers.md +++ b/source/zh-tw/docs/helpers.md @@ -192,7 +192,7 @@ title: 輔助函數(Helpers) 檢查目前是否為文章。 ``` js -<%- is_home() %> +<%- is_post() %> ``` ### is_archive @@ -200,7 +200,7 @@ title: 輔助函數(Helpers) 檢查目前是否為彙整頁面。 ``` js -<%- is_home() %> +<%- is_archive() %> ``` ### is_year @@ -208,7 +208,7 @@ title: 輔助函數(Helpers) 檢查目前是否為年度彙整頁面。 ``` js -<%- is_home() %> +<%- is_year() %> ``` ### is_month @@ -216,7 +216,7 @@ title: 輔助函數(Helpers) 檢查目前是否為每月彙整頁面。 ``` js -<%- is_home() %> +<%- is_month() %> ``` ### is_category @@ -224,7 +224,7 @@ title: 輔助函數(Helpers) 檢查目前是否為分類彙整頁面。 ``` js -<%- is_home() %> +<%- is_category() %> ``` ### is_tag @@ -232,7 +232,7 @@ title: 輔助函數(Helpers) 檢查目前是否為標籤彙整頁面。 ``` js -<%- is_home() %> +<%- is_tag() %> ``` ## 字串處理 @@ -373,10 +373,10 @@ title: 輔助函數(Helpers) ``` js <%- date(Date.now()) %> -// Jan 1, 2013 +// 2013-01-01 -<%- date(Date.now(), 'YYYY/M/D') %> -// 2013/1/1 +<%- date(Date.now(), 'MMM D YYYY') %> +// Jan 1 2013 ``` ### date_xml @@ -604,7 +604,7 @@ title: 輔助函數(Helpers) ### open_graph -插入 open graph 資料。 +插入 [Open Graph] 資料。 ``` js <%- open_graph([options]) %> @@ -645,4 +645,5 @@ title: 輔助函數(Helpers) ``` [顏色關鍵字]: http://www.w3.org/TR/css3-color/#svg-color -[Moment.js]: http://momentjs.com/ \ No newline at end of file +[Moment.js]: http://momentjs.com/ +[Open Graph]: http://ogp.me/ \ No newline at end of file diff --git a/source/zh-tw/docs/index.md b/source/zh-tw/docs/index.md index dfc9c0ce15..42a50e61b7 100644 --- a/source/zh-tw/docs/index.md +++ b/source/zh-tw/docs/index.md @@ -20,7 +20,7 @@ Hexo 是一個快速、簡單且強大的網誌框架。Hexo 使用 [Markdown](h 若您的電腦已經安裝上述的必備軟體,那麼恭喜您!只需要透過 npm 即可完成 Hexo 的安裝。 ``` bash -$ npm install -g hexo +$ npm install -g hexo-cli ``` 如果您的電腦尚未安裝必備軟體的話,請根據下列的安裝指示來完成安裝。 @@ -55,7 +55,7 @@ $ wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh 一旦安裝完成,重啟終端機並執行下列指令以安裝 Node.js。 ``` bash -$ nvm install 0.10 +$ nvm install 0.12 ``` 或者您也可以下載 [安裝程式](http://nodejs.org/) 來安裝。 @@ -65,5 +65,5 @@ $ nvm install 0.10 一旦所有的必備軟體都安裝完畢後,即可透過 npm 安裝 Hexo。 ``` bash -$ npm install -g hexo -``` +$ npm install -g hexo-cli +``` \ No newline at end of file diff --git a/source/zh-tw/docs/models.md b/source/zh-tw/docs/models.md deleted file mode 100644 index 382674e846..0000000000 --- a/source/zh-tw/docs/models.md +++ /dev/null @@ -1,67 +0,0 @@ -title: Models ---- -Hexo uses [Warehouse](https://github.com/tommy351/warehouse) to store everything. You can check the [API](/api/warehouse/classes/Database.html) and see the contents of data model below. - -### Post - -Name | Description ---- | --- -`id` | Post ID (Set by user) -`title` | Post title -`date` | Post date ([Moment.js] object) -`updated` | Post last updated date ([Moment.js] object) -`categories` | All categories of the post -`tags` | All tags of the post -`comments` | Comment enabled or not -`layout` | Layout name -`content` | The full processed content of the post -`excerpt` | The processed excerpt of the post -`source` | The path of the source file -`full_source` | Full path of the source file -`path` | The URL of the post without root URL -`permalink` | Full URL of the post -`raw` | The raw data of the post -`photos` | The photos of the article (Used in gallery posts) -`link` | The external link of the article (Used in link posts) - -### Page - -Name | Description ---- | --- -`title` | Page title -`date` | Page date ([Moment.js] object) -`updated` | Page last updated date ([Moment.js] object) -`comments` | Comment enabled or not -`layout` | Layout name -`content` | The full processed content of the page -`excerpt` | The processed excerpt of the page -`source` | The path of the source file -`full_path` | Full path of the source file -`path` | The URL of the page without root URL -`permalink` | Full URL of the page -`raw` | The raw data of the page - -### Category - -Name | Description ---- | --- -`name` | Category name -`slug` | Category slug -`posts` | All posts in the category -`path` | The URL of the category without root URL -`permalink` | Full URL of the category -`length` | Total number of posts in the category -`parent` | Parent category - -### Tag - -Name | Description ---- | --- -`name` | Tag name -`slug` | Tag slug -`posts` | All posts in the tag -`path` | The URL of the tag without root URL -`permalink` | Full URL of the tag -`length` | Total number of posts in the tag - -[Moment.js]: http://momentjs.com/ \ No newline at end of file diff --git a/source/zh-tw/docs/pagination.md b/source/zh-tw/docs/pagination.md deleted file mode 100644 index b1221f1b86..0000000000 --- a/source/zh-tw/docs/pagination.md +++ /dev/null @@ -1,44 +0,0 @@ -title: Pagination ---- -When there're many posts in your blog, it's useful to separate into several pages. Hexo supports pagination. The following is how you can use pagination in Hexo. - -Before we start, you have to enable pagination. Edit `per_page` setting to change how many posts displayed in a single page. To disable pagination, just set it to `0`. - -``` yaml -per_page: 10 -``` - -You can edit the following setting to enable or disable pagination for specific pages. - -- 2: Enable pagination -- 1: Disable pagination -- 0: Fully disable - -``` yaml -archive: 2 -category: 2 -tag: 2 -``` - -## Basic - -The most basic pagination is just two links: "Previous page" & "Next page". For example: - -``` -<% if (page.prev){ %> - <a href="<%- url_for(page.prev_link) %>">Prev</a> -<% } %> -<% if (page.next){ %> - <a href="<%- url_for(page.next_link) %>">Next</a> -<% } %> -``` - -## Paginator helper - -To display pagination in number. You can use paginator helper. It helps you insert pagination fast. - -``` -<%- paginator() %> -``` - -For more info, see [Helpers](/docs/helpers.html#paginator). diff --git a/source/zh-tw/docs/plugins.md b/source/zh-tw/docs/plugins.md index 9b5d08d39e..37c18b9676 100644 --- a/source/zh-tw/docs/plugins.md +++ b/source/zh-tw/docs/plugins.md @@ -4,11 +4,13 @@ Hexo 有強大的外掛系統,使您能輕鬆擴展功能而不用修改核心 ### 腳本(Scripts) -如果您的程式碼很簡單,建議您撰寫腳本,您只需要把 JavaScript 檔案放到 `scripts` 資料夾,在啟動時就會自動載入。 +如果您的程式碼很簡單,建議您撰寫腳本,您只需要把 JavaScript 檔案放到 `scripts` 資料夾,在啟動時就會自動載入一次。 ### 套件(Packages) -如果您的程式碼較複雜,或是您想要發佈到 NPM 上,建議您撰寫套件。首先,在 `node_modules` 資料夾中建立資料夾,資料夾名稱開頭必須為 `hexo-`,如此一來 Hexo 才會在啟動時載入。資料夾內至少要包含 2 個檔案:一個是主程式,另一個是 `package.json`,描述套件的用途和相依套件。 +如果您的程式碼較複雜,或是您想要發佈到 NPM 上,建議您撰寫套件。首先,在 `node_modules` 資料夾中建立資料夾,資料夾名稱開頭必須為 `hexo-`,如此一來 Hexo 才會在啟動時載入。 + +資料夾內至少要包含 2 個檔案:一個是主程式,另一個是 `package.json`,描述套件的用途和相依套件。 ``` plain . @@ -51,7 +53,34 @@ Hexo 共有九種外掛,您可以在 API 頁面中獲得更多資訊: ### 發佈 -[hexo-fs]: https://github.com/hexojs/fs -[hexo-util]: https://github.com/hexojs/util -[hexo-i18n]: https://github.com/hexojs/i18n -[hexo-pagination]: https://github.com/hexojs/hexo-pagination \ No newline at end of file +當您完成外掛後,可以考慮將它發佈到 [外掛列表](/plugins),讓更多人能夠使用您的外掛。發佈外掛的步驟和 [更新文件](contributing.html#更新文件) 非常類似。 + +1. Fork [hexojs/site] +2. 把檔案庫(repository)複製到電腦上,並安裝相依套件。 + + {% code %} + $ git clone https://github.com/<username>/site.git + $ cd site + $ npm install + {% endcode %} + +3. 編輯 `source/_data/plugins.yml`,在檔案中新增您的外掛,例如: + + {% code %} + - name: hexo-server + description: Server module for Hexo. + link: https://github.com/hexojs/hexo-server + tags: + - official + - server + - console + {% endcode %} + +4. 推送(push)分支。 +5. 建立一個新的合併申請(pull request)。 + +[hexo-fs]: https://github.com/hexojs/hexo-fs +[hexo-util]: https://github.com/hexojs/hexo-util +[hexo-i18n]: https://github.com/hexojs/hexo-i18n +[hexo-pagination]: https://github.com/hexojs/hexo-pagination +[hexojs/site]: https://github.com/hexojs/site \ No newline at end of file diff --git a/source/zh-tw/docs/server.md b/source/zh-tw/docs/server.md index a5b9f4c0f0..9c87a990c8 100644 --- a/source/zh-tw/docs/server.md +++ b/source/zh-tw/docs/server.md @@ -2,19 +2,19 @@ title: Server --- ## [hexo-server] -Hexo 3.0 把伺服器獨立成個別模組,您必須先安裝 [hexo-server] 才能使用。 +Hexo 3 把伺服器獨立成個別模組,您必須先安裝 [hexo-server] 才能使用。 ``` bash $ npm install hexo-server --save ``` -安裝完畢後,輸入以下指令以啟動伺服器,您的網站會在 `http://localhost:4000`,在伺服器啟動期間,Hexo 會監看檔案變動並自動更新,您無須重啟伺服器。 +安裝完畢後,輸入以下指令以啟動伺服器,您的網站預設會執行於 `http://localhost:4000`,在伺服器啟動期間,Hexo 會監看檔案變動並自動更新,您無須重啟伺服器。 ``` bash $ hexo server ``` -如果您想要變更連接埠,或是在執行時遇到了 `EADDRINUSE` 錯誤,可以在執行時使用 `-p` 選項指定其他連接埠,如下: +如果您想要變更連接埠,或是在執行時遇到了 `EADDRINUSE` 錯誤,可以在執行時使用 `-p` 選項指定其他連接埠。 ``` bash $ hexo server -p 5000 @@ -22,7 +22,7 @@ $ hexo server -p 5000 ### 靜態模式 -在靜態模式下,伺服器只會處理 `public` 資料夾內的檔案,而且不會處理檔案變動,在執行時,您應該先自行執行 `hexo generate`,此模式通常用於生產環境(production mode)下。 +在靜態模式下,伺服器只會處理 `public` 資料夾內的檔案,而且不會處理檔案變動,在執行時,您應該先自行執行 `hexo generate`,此模式通常用於生產環境(production)下。 ``` bash $ hexo server -s @@ -30,7 +30,7 @@ $ hexo server -s ### 自定 IP -伺服器預設運作在 `0.0.0.0`,您可以覆蓋預設的 IP 設定,如下: +伺服器預設運作在 `0.0.0.0`,您可以覆蓋預設的 IP 設定。 ``` bash $ hexo server -i 192.168.1.1 @@ -38,7 +38,7 @@ $ hexo server -i 192.168.1.1 ## Pow -[Pow](http://pow.cx/) 是一個 Mac 系統上的零配置 Rack 伺服器,它也可作為一個簡單易用的靜態檔案伺服器來使用。 +[Pow] 是一個 Mac 系統上的零配置 Rack 伺服器,它也可作為一個簡單易用的靜態檔案伺服器來使用。 ### 安裝 @@ -57,35 +57,5 @@ $ ln -s /path/to/myapp 您的網站將會執行於 `http://myapp.dev`,網址是根據連結名稱而定。 -## Forever / PM2 - -To keep the Hexo server alive, you can use [Forever] or [PM2]. - -Hexo can be run programmatically since 2.5. So you can call Hexo in JavaScript instead of CLI. - -**1. Install Hexo in the folder of your site.** - -``` bash -$ npm install hexo --save -``` - -**2. Add a JavaScript file with the following content.** - -``` js app.js -require('hexo').init({command: 'server'}); -``` - -**3. Run the JavaScript file you just created with [Forever] or [PM2].** - -PM2 has a [known issue](https://github.com/Unitech/pm2#known-bugs-and-workarounds) that the port isn't released when the script is stopped unless PM2 is killed. You have to run the script in fork mode. - -``` bash -$ forever start app.js -$ pm2 start app.js -x -``` - [hexo-server]: https://github.com/hexojs/hexo-server -[Connect]: https://github.com/senchalabs/connect -[morgan]: https://github.com/expressjs/morgan -[Forever]: https://github.com/nodejitsu/forever -[PM2]: https://github.com/Unitech/pm2 \ No newline at end of file +[Pow]: http://pow.cx/ \ No newline at end of file diff --git a/source/zh-tw/docs/setup.md b/source/zh-tw/docs/setup.md index ad98d06e13..185ba6ba94 100644 --- a/source/zh-tw/docs/setup.md +++ b/source/zh-tw/docs/setup.md @@ -33,26 +33,32 @@ $ npm install ``` json package.json { "name": "hexo-site", - "version": "", + "version": "0.0.0", "private": true, "hexo": { "version": "" }, "dependencies": { - "hexo-renderer-ejs": "*", - "hexo-renderer-stylus": "*", - "hexo-renderer-marked": "*" + "hexo": "^3.0.0", + "hexo-generator-archive": "^0.1.0", + "hexo-generator-category": "^0.1.0", + "hexo-generator-index": "^0.1.0", + "hexo-generator-tag": "^0.1.0", + "hexo-renderer-ejs": "^0.1.0", + "hexo-renderer-stylus": "^0.2.0", + "hexo-renderer-marked": "^0.2.4", + "hexo-server": "^0.1.2" } } ``` ### scaffolds -[鷹架](writing.html) 資料夾。當您建立新文章時,Hexo 會根據 scaffold 來建立檔案。 +[鷹架](writing.html#鷹架(Scaffold)) 資料夾。當您建立新文章時,Hexo 會根據 scaffold 來建立檔案。 ### scripts -[腳本](plugins.html) 資料夾。腳本是擴充 Hexo 的最簡易方式,在此資料夾內的 JavaScript 檔案會被自動執行。 +[腳本](plugins.html#腳本(Scripts)) 資料夾。腳本是擴充 Hexo 的最簡易方式,在此資料夾內的 JavaScript 檔案會被自動執行。 ### source diff --git a/source/zh-tw/docs/themes.md b/source/zh-tw/docs/themes.md index 25075a2715..c34b6cee99 100644 --- a/source/zh-tw/docs/themes.md +++ b/source/zh-tw/docs/themes.md @@ -1,6 +1,6 @@ title: 主題 --- -打造 Hexo 主題非常容易,您只要在 `themes` 資料夾內,新增一個任意名稱的資料夾,並修改 `_config.yml` 內的 `theme` 設定,即可切換主題。一個主題可能會有以下的結構: +打造 Hexo 主題非常容易,您只要在 `themes` 資料夾內,新增一個資料夾,並修改 `_config.yml` 內的 `theme` 設定,即可切換主題。一個主題可能會有以下的結構: ``` plain . @@ -42,7 +42,38 @@ Swig: layout.swig ### 發佈 +當您完成主題後,可以考慮將它發佈到 [主題列表](/themes),讓更多人能夠使用您的主題,在發佈前建議先進行 [主題單元測試](https://github.com/hexojs/hexo-theme-unit-test),確保每一項功能都能正常運作。發佈主題的步驟和 [更新文件](contributing.html#更新文件) 非常類似。 + +1. Fork [hexojs/site] +2. 把檔案庫(repository)複製到電腦上,並安裝相依套件。 + + {% code %} + $ git clone https://github.com/<username>/site.git + $ cd site + $ npm install + {% endcode %} + +3. 編輯 `source/_data/themes.yml`,在檔案中新增您的主題,例如: + + {% code %} + - name: landscape + description: A brand new default theme for Hexo. + link: https://github.com/hexojs/hexo-theme-landscape + preview: http://hexo.io/hexo-theme-landscape + tags: + - official + - responsive + - widget + - two_column + - one_column + {% endcode %} + +4. 在 `source/themes/screenshots` 新增同名的截圖檔案,圖片必須為 800x500 的 PNG 檔案。 +5. 推送(push)分支。 +6. 建立一個新的合併申請(pull request)。 + [EJS]: https://github.com/hexojs/hexo-renderer-ejs [Swig]: http://paularmstrong.github.com/swig/ [Haml]: https://github.com/hexojs/hexo-renderer-haml -[Jade]: https://github.com/hexojs/hexo-renderer-jade \ No newline at end of file +[Jade]: https://github.com/hexojs/hexo-renderer-jade +[hexojs/site]: https://github.com/hexojs/site \ No newline at end of file diff --git a/source/zh-tw/docs/writing.md b/source/zh-tw/docs/writing.md index 0272428be9..122d4c4ee0 100644 --- a/source/zh-tw/docs/writing.md +++ b/source/zh-tw/docs/writing.md @@ -8,7 +8,7 @@ $ hexo new [layout] <title> 您可以在指令中指定文章的佈局(layout),預設為 `post`,您可以透過修改 `_config.yml` 中的 `default_layout` 設定來指定預設佈局。 -## 佈局(Layout) +### 佈局(Layout) Hexo 有三種預設佈局:`post`、`page` 和 `draft`,它們分別對應不同的路徑,而您所自定的其他佈局和 `post` 相同,都儲存至 `source/_posts` 資料夾。 @@ -18,7 +18,7 @@ Hexo 有三種預設佈局:`post`、`page` 和 `draft`,它們分別對應不 `page` | `source` `draft` | `source/_drafts` -## 檔案名稱 +### 檔案名稱 Hexo 預設以標題做為檔案名稱,但您可編輯 `new_post_name` 設定來變更預設的檔案名稱,舉例來說,設為 `:year-:month-:day-:title.md` 可讓您更方便的透過日期來管理文章。 @@ -31,7 +31,7 @@ Hexo 預設以標題做為檔案名稱,但您可編輯 `new_post_name` 設定 `:day` | 建立日期(2 位數) `:i_day` | 建立日期(去掉開頭的零) -## 草稿 +### 草稿 剛剛提到了 Hexo 的一種特殊佈局:`draft`,這種佈局在建立時會被儲存於 `source/_drafts` 資料夾,您可透過 `publish` 指令將草稿移動到 `source/_posts` 資料夾,這項指令的使用方式與 `new` 十分類似,您也可在指令中指定 `layout` 來指定佈局。 @@ -41,7 +41,7 @@ $ hexo publish [layout] <title> 草稿預設不會顯示於頁面中,您可在執行時加上 `--draft` 選項,或是把 `render_drafts` 設定改為 `true` 來預覽草稿。 -## 鷹架(Scaffold) +### 鷹架(Scaffold) 在建立文章時,Hexo 會根據 `scaffolds` 資料夾內相對應的檔案來建立檔案,例如: diff --git a/themes/navy/layout/partial/head.swig b/themes/navy/layout/partial/head.swig index 7de5bb9374..fcb12754af 100644 --- a/themes/navy/layout/partial/head.swig +++ b/themes/navy/layout/partial/head.swig @@ -1,6 +1,6 @@ <head prefix="og: http://ogp.me/ns#"> <meta charset="utf-8"> - <title>{% if page.title %}{{ page.title }} | {% endif %}Hexo + {% if page.title %}{{ page.title }} | {% endif %}{{ config.title }} diff --git a/themes/navy/source/css/_partial/common.styl b/themes/navy/source/css/_partial/common.styl index 524ba00ceb..0e328c4c25 100644 --- a/themes/navy/source/css/_partial/common.styl +++ b/themes/navy/source/css/_partial/common.styl @@ -4,12 +4,20 @@ html *, *:before, *:after box-sizing: inherit -input, button +button +input[type="reset"] +input[type="button"] +input[type="submit"] &::-moz-focus-inner padding: 0 margin: 0 border: 0 +input, button, select + margin: 0 + padding: 0 + border: 0 + body background: color-navy font-size: font-size @@ -32,4 +40,4 @@ body background: #fff border-top: 1px solid darken(color-navy, 5%) border-bottom: 1px solid darken(color-navy, 5%) - margin: -1px 0 + margin: -1px 0 \ No newline at end of file