Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(full_url_for): utilize hexo-util module #3701

Merged
merged 4 commits into from
Sep 17, 2019

Conversation

SukkaW
Copy link
Member

@SukkaW SukkaW commented Sep 2, 2019

What does it do?

hexojs/hexo-util#84

Returns a url with the config.url prefixed.

Use Case 1

link[canonical] tag, which is one of a best practice for SEO, needs an absolute url of current page.

According to the test carried out by theme NexT team:

{{ page.permalink }} works on every page exclude index and archive page.
{{ url }} is everywhere.

A full_url_for(page.path) can be used in this case.

Use Case 2

Use url to share the post at social media, which is similar to the first case:

  • Sina Weibo http://service.weibo.com/share/share.php?appkey=&title=[title]&url=[url]&pic=[site logo]&searchPic=false&style=simple
  • Twitter https://twitter.com/intent/tweet?text=[title]&url=[url]
  • Facebook https://www.facebook.com/sharer/sharer.php?u=[url]
  • Telegram https://t.me/share/url?url=[url]&text=[title]

Absolute urls are needed for [url] and [site logo], and full_url_for(page.path) & full_url_for(${site_logo_url}) can be used.

Use Case 3

All examples of structured data (Image, Page path...) and open-graph use absolute urls. If they are best practices, then full_url_for helper can be used.

How to test

git clone -b full_url_for https://github.com/sukkaw/hexo.git
cd hexo
npm install
npm test

Screenshots

I have implemented a _full_url_for for my suka theme and it works perfectly.

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

@SukkaW SukkaW added this to the Candidate next release milestone Sep 2, 2019
@coveralls
Copy link

coveralls commented Sep 2, 2019

Coverage Status

Coverage increased (+0.003%) to 97.222% when pulling bfd8b0a on SukkaW:full_url_for into bc474dc on hexojs:master.

@SukkaW
Copy link
Member Author

SukkaW commented Sep 4, 2019

This might be a alternate solution for #3604

@SukkaW
Copy link
Member Author

SukkaW commented Sep 15, 2019

Test will be passed after hexo's dependencies updates.

@SukkaW SukkaW changed the title feat(helper): bring up a full_url_for helper feat(full_url_for): utilize hexo-util module Sep 15, 2019
@SukkaW SukkaW requested a review from a team September 15, 2019 13:53
'use strict';
const { full_url_for } = require('hexo-util');

module.exports = function(path = '/') {
Copy link
Contributor

@curbengh curbengh Sep 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be just path, hexo-util.full_url_for() already set default parameter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, and related test has been added.

@curbengh
Copy link
Contributor

curbengh commented Sep 15, 2019

Test will be passed after hexo's dependencies updates.

Just update hexo-util to ^1.2.0.

https://github.com/hexojs/hexo/pull/3710/files#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R48


I'll merge this for v4. @SukkaW

tomap
tomap previously approved these changes Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants