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

fix : add feed icon to rss2.xml #102

Merged
merged 10 commits into from
Nov 5, 2019
Merged

fix : add feed icon to rss2.xml #102

merged 10 commits into from
Nov 5, 2019

Conversation

sehajyang
Copy link
Contributor

@sehajyang sehajyang commented Oct 30, 2019

I configured feed.icon in the config.yml file.
but that icon was not exposed when creating the feed xml file.
So, I add in rss2.xml :

<url> {{(url + config.feed.icon) | uriencode}} </ url>

and I see that it works.

I configured `feed.icon` in the `config.yml` file but that icon was not exposed when creating the feed xml file.
So, I Add in rss2.xml `<url> {{(url + config.feed.icon) | uriencode}} </ url>` and I see that it works.
@coveralls
Copy link

coveralls commented Oct 30, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 417898d on sehajyang:patch-1 into d169992 on hexojs:master.

Copy link
Member

@SukkaW SukkaW left a comment

Choose a reason for hiding this comment

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

After this change, it will become impposible to use third-party url of feed icon.

Please use full_url_for() instead.

@sehajyang
Copy link
Contributor Author

sehajyang commented Oct 30, 2019

full_url_for() seems to add the blog url as a prefix.
So if it's a third-party url, it seems to be blog url + third-party url. am I right?

@sehajyang
Copy link
Contributor Author

@sukka

I installed hexo-util and added the following code to generator.js:

const all_url_for = require ('hexo-util'). all_url_for.bind (hexo);

var icon;
if (config.email) {
    icon = gravatar (config.email)
} else {
    icon = all_url_for (config.feed.icon)
}

However, there was an error where config could not be found in all_url_for ().
Also bind (hexo); didn't work. I tried a few ways to solve this problem but it failed.
How can i use all_url_for?

@SukkaW
Copy link
Member

SukkaW commented Oct 30, 2019

@sehajyang Try this?

First, require full_url_for at the beginning:

const { encodeURL, gravatar } = require('hexo-util');

 const { encodeURL, gravatar, full_url_for } = require('hexo-util'); 

Then change L38:

if (feedConfig.icon) icon = url + encodeURI(feedConfig.icon);

to:

if (feedConfig.icon) icon = encodeURI(full_utl_for.call(this, feedConfig.icon)); 

You can also include shorter object syntax in this PR:

const xml = template.render({
config: config,
url: url,
icon: icon,
posts: posts,
feed_url: config.root + feedConfig.path
});

to

 const xml = template.render({ 
   config, 
   url, 
   icon, 
   posts, 
   feed_url: config.root + feedConfig.path 
 }); 

@sehajyang sehajyang requested a review from SukkaW October 30, 2019 08:04
@sehajyang
Copy link
Contributor Author

sehajyang commented Oct 30, 2019

@SukkaW
I fixed it as your comment and saw that it works.
Thanks to your comment I was able to solve this issue. Thank you for your help 😊

lib/generator.js Outdated Show resolved Hide resolved
rss2.xml Outdated Show resolved Hide resolved
@curbengh
Copy link
Contributor

curbengh commented Nov 3, 2019

Unit test is also missing, let me know if you need help creating one.

@sehajyang
Copy link
Contributor Author

sehajyang commented Nov 4, 2019

@curbengh
Yes I need help. Can you make one?
Also, I modified the part you commented above. Let me know if there's anything I need to change.

rss2.xml Show resolved Hide resolved
@curbengh
Copy link
Contributor

curbengh commented Nov 5, 2019

I just added two tests, for atom only. Simply duplicate them (not replace), change the necessary config to rss2 then change the corresponding expected result.

A brief guide for using cheerio; atom.xml starts with the following value,

<feed xmlns="https://www.w3.org/2005/Atom">
  <title>{{ config.title }}</title>
  <icon>{{ icon }}</icon>

Notice $('feed>icon') corresponds to the <feed> and <icon> elements. The > is a shortcut for .children(); in this case, we're looking for <icon> in the children of <feed>.

Hint: for subsequent levels,

<feed xmlns="https://www.w3.org/2005/Atom">
  <title>{{ config.title }}</title>
  <foo>
    <bar>baz</bar>
  <foo>
$('feed>foo>bar').text()
// baz

atom.xml Outdated Show resolved Hide resolved
@sehajyang
Copy link
Contributor Author

sehajyang commented Nov 5, 2019

@curbengh
I created the rss2 icon's test code with your comments and the atom icon's test code.
Thank you for your help.
Please let me know if there are any errors.

@curbengh curbengh merged commit d168026 into hexojs:master Nov 5, 2019
@sehajyang sehajyang deleted the patch-1 branch November 5, 2019 05:11
@sehajyang sehajyang changed the title Add : feed icon to rss2.xml fix : add feed icon to rss2.xml Dec 27, 2019
darekkay added a commit to darekkay/hexo-generator-feed that referenced this pull request May 26, 2020
This PR is an update to hexojs#29.

This supposed to be a small PR, but I've encountered some issues regarding the base URL.

The `[full_url_for](https://github.com/hexojs/hexo-util/blob/master/lib/full_url_for.js#L27)` function expects the `config.url` not to end with a forward slash. Otherwise it will create a double slash URL, e.g. `http://example.com//atom.xml` (notice that a double slash replacement happens only _after_ the base URL).

I was wondering how the icon feature (hexojs#102) can be using `full_url_for` with the current code and not run into any double slash issues. The answer is: it doesn't handle this case. The [unit tests](https://github.com/hexojs/hexo-generator-feed/pull/102/files#diff-910eb6f57886ca16c136101fb1699231R240) are simply running against a custom base URL without an ending slash.

I've cleaned up the tests:
- removed the ending slash from the base URL
- adjusted and added new tests to handle subdirectories correctly (as specified in the [hexo documentation](https://hexo.io/docs/configuration.html#URL))
- hard-coded expected values - it makes a test more reliable and readable
darekkay added a commit to darekkay/hexo-generator-feed that referenced this pull request May 26, 2020
This PR is an update to hexojs#29.

This supposed to be a small PR, but I've encountered some issues regarding the base URL.

The `[full_url_for](https://github.com/hexojs/hexo-util/blob/master/lib/full_url_for.js#L27)` function expects the `config.url` not to end with a forward slash. Otherwise it will create a double slash URL, e.g. `http://example.com//atom.xml` (notice that a double slash replacement happens only _after_ the base URL).

I was wondering how the icon feature (hexojs#102) can be using `full_url_for` with the current code and not run into any double slash issues. The answer is: it doesn't handle this case. The [unit tests](https://github.com/hexojs/hexo-generator-feed/pull/102/files#diff-910eb6f57886ca16c136101fb1699231R240) are simply running against a custom base URL without an ending slash.

I've cleaned up the tests:
- removed the ending slash from the base URL
- adjusted and added new tests to handle subdirectories correctly (as specified in the [hexo documentation](https://hexo.io/docs/configuration.html#URL))
- hard-coded expected values - it makes a test more reliable and readable
SukkaW pushed a commit that referenced this pull request Jun 1, 2020
This PR is an update to #29.

This supposed to be a small PR, but I've encountered some issues regarding the base URL.

The `[full_url_for](https://github.com/hexojs/hexo-util/blob/master/lib/full_url_for.js#L27)` function expects the `config.url` not to end with a forward slash. Otherwise it will create a double slash URL, e.g. `http://example.com//atom.xml` (notice that a double slash replacement happens only _after_ the base URL).

I was wondering how the icon feature (#102) can be using `full_url_for` with the current code and not run into any double slash issues. The answer is: it doesn't handle this case. The [unit tests](https://github.com/hexojs/hexo-generator-feed/pull/102/files#diff-910eb6f57886ca16c136101fb1699231R240) are simply running against a custom base URL without an ending slash.

I've cleaned up the tests:
- removed the ending slash from the base URL
- adjusted and added new tests to handle subdirectories correctly (as specified in the [hexo documentation](https://hexo.io/docs/configuration.html#URL))
- hard-coded expected values - it makes a test more reliable and readable
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