Hexo: How to link a post with another post ?

Created on 23 Sep 2016  ·  14Comments  ·  Source: hexojs/hexo

before you submit your issue, please delete all the example code in template

Environment Info

Node version(node -v)

v4.5.0

Your site _config.yml

# Hexo Configuration
...

Your theme _config.yml

# Hexo Configuration
...

Plugin version(npm ls --depth 0)

[email protected] ~/hexo-vanilla-site
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

For BUG

  • BUG description
  • the way to reproduce
  • log with hexo --debug

    For question

just push question

For feature request

just push feature request

Most helpful comment

Use a post link tag plugin:

{% post_path slug %}
{% post_link slug [title] %}

example, if your post's file name is hello-world.md

{% post_link hello-world %}

All 14 comments

I tried this:
[title](2016/09/23/name/index.html)
but its too dependant of the date
does an automatic function for referencing ?

You could change the permalink in your _config.yml.

In your post front matters, you could add variables that will use in the permalink, but be sure they will be unique for each post.

title: testMD
date: 2016-09-29T10:46:39.000Z
tags: null
ArticleID: 1
---

Then the permanlink: permanlink: :ArticleID

Now, your post URL for the testMD will be http://yourdomain/1/

To avoid manually increase the ID number, you could try this plugin https://github.com/Rozbo/hexo-abbrlink , which will generate random number for your posts and keep them unique to each other.

Thank you for your suggestion.
Is it also valid for:
post -> page
page -> post
page -> page

Not exactly.

Comparing post, Hexo handle page differently. The permanlink setting is only effect the posts. The page url is usually the title, like http://yourdomian/pageTitle/.

Hello again,
I tried your suggestion (hexo-abbrlink)
1) installation

npm install hexo-fs --save
npm install hexo-front-matter --save
npm instann hexo-abbrlink --save

2) configuration (_config_yml)

permalink: posts/:abbrlink/
abbrlink:
 alg: crc16
 rep: dec

3) generation
hexo generate
All my posts have in their front matter a new field, ie:

abbrlink: 9399

4) usage
In the #9399 post, I call the #60911 post:
hello [post](/60911/) <<< that doesn't work !
after translation:
hello www.mydomain/posts/9399/60911

This is really weird. I couldn't reproduce the issue.

Could you please paste your _config.yml?

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title:
subtitle:
description: test du produit hexo
author:
language: fr
timezone: Europe/Zurich

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child$
url: http://xxxxx.com
root: /
permalink: posts/:abbrlink/
#:year/:month/:day/:title/
permalink_defaults:
# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: true
  line_number: true
  auto_detect: false
  tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:
- hexo
- création
- blog

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: DD-MM-YYYY
# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape
#theme: alpha-dust
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: ftpsync
  host: ftp.xxxxxxxx.com
  user: yyyyyyyyyy
  pass: zzzzzzzzzz
  verbose: true
  ignore: ['recuperation','blog','blog1']
  remote: '/web/'


#sitemap
sitemap:
 path:sitemap.xml

#feed
feed:
 type:atom
 path:atom.xml
 limit:20

category_generator:
 par_page:10

abbrlink:
  alg: crc16
  rep: dec



I tried your config file, everything works well.

repeat me how you use it ...

I don't have a Debian environment, so all the tests are on Mac OS. Other than that, I copied and pasted your _config.yml and create the similar scenario. I didn't see the link error as you stated.

Ok but I suppose you are using a markdown editor. What syntax are you using for calling a post ?
[title](/abbrlink_number/) doesn't work

Yeah, exactly. After rendering, it becomes http://domain/abbrlink_number/.

Not for me !
It becomes: http://domain/abbrlink_number_of_the_caller/abbrlink_number_of_the_called/.

Use a post link tag plugin:

{% post_path slug %}
{% post_link slug [title] %}

example, if your post's file name is hello-world.md

{% post_link hello-world %}
Was this page helpful?
0 / 5 - 0 ratings