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

Allow open_graph generates meta tag "keywords" by page.keywords, page.tags or config.keywords #2535

Merged
merged 7 commits into from
Apr 26, 2017

Conversation

restran
Copy link
Contributor

@restran restran commented Apr 25, 2017

The open_graph generates HTML meta tag "keywords" only according to page.tags. Allow HTML meta tag "keywords" generated in order of page.keywords, page.tags and config.keywords could be more flexible.

// mypost.md
// custom keywords for html meta tag "keywords"
keywords: [web, site, hexo]
tags: [web, site]

If no keywords or tags specified in page, keywords in _config.js will be used.

// _config.js
keywords: blog, hexo, site
var keywords = page.keywords || (page.tags && page.tags.length ? page.tags : undefined) || config.keywords;

I also check the type of keywords to support string or array.

  if (keywords) {
    if (typeof keywords === 'string') {
      result += meta('keywords', keywords);
    } else if (keywords.length) {
      result += meta('keywords', keywords.map(function(tag) {
        return tag.name ? tag.name : tag;
      }).filter(function(keyword) {
        return !!keyword;
      }).join());
    }
  }

I also add escapeHTML to the content of meta tag in consider of avoiding XSS issue. These characters ' "
<> & / in content of meta tag should be escaped.

var escapeHTML = util.escapeHTML;

function meta(name, content, escape) {
  if (escape !== false) {
    content = escapeHTML(content);
  }

  return htmlTag('meta', {
    name: name,
    content: content
  }) + '\n';
}

function og(name, content, escape) {
  if (escape !== false) {
    content = escapeHTML(content);
  }

  return htmlTag('meta', {
    property: name,
    content: content
  }) + '\n';
}
  • Add test cases for the changes.
  • Passed the CI test.

@coveralls
Copy link

coveralls commented Apr 25, 2017

Coverage Status

Coverage decreased (-0.6%) to 96.632% when pulling e3aff27 on restran:feature_open_graph into fbdee90 on hexojs:master.

@restran restran closed this Apr 25, 2017
@restran restran reopened this Apr 25, 2017
@coveralls
Copy link

coveralls commented Apr 25, 2017

Coverage Status

Coverage decreased (-0.6%) to 96.632% when pulling 800aa7e on restran:feature_open_graph into fbdee90 on hexojs:master.

@coveralls
Copy link

coveralls commented Apr 25, 2017

Coverage Status

Coverage decreased (-0.6%) to 96.632% when pulling 800aa7e on restran:feature_open_graph into fbdee90 on hexojs:master.

@restran restran changed the title Allow open_graph generates meta tag "keywords" by page.keywords, page.tags or theme.keywords Allow open_graph generates meta tag "keywords" by page.keywords, page.tags or config.keywords Apr 25, 2017
@coveralls
Copy link

coveralls commented Apr 25, 2017

Coverage Status

Coverage decreased (-0.02%) to 97.163% when pulling dc99384 on restran:feature_open_graph into fbdee90 on hexojs:master.

@coveralls
Copy link

coveralls commented Apr 25, 2017

Coverage Status

Coverage decreased (-0.02%) to 97.163% when pulling b011003 on restran:feature_open_graph into fbdee90 on hexojs:master.

@coveralls
Copy link

coveralls commented Apr 25, 2017

Coverage Status

Coverage decreased (-0.02%) to 97.163% when pulling e644997 on restran:feature_open_graph into fbdee90 on hexojs:master.

Copy link
Member

@NoahDragon NoahDragon left a comment

Choose a reason for hiding this comment

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

Could please add the test cases?

@restran
Copy link
Contributor Author

restran commented Apr 25, 2017

@NoahDragon OK, i will do it later.

@NoahDragon
Copy link
Member

@restran Thank you. 👍

@coveralls
Copy link

coveralls commented Apr 26, 2017

Coverage Status

Coverage increased (+0.006%) to 97.188% when pulling f41b583 on restran:feature_open_graph into fbdee90 on hexojs:master.

@coveralls
Copy link

coveralls commented Apr 26, 2017

Coverage Status

Coverage increased (+0.006%) to 97.188% when pulling 768e567 on restran:feature_open_graph into fbdee90 on hexojs:master.

@restran
Copy link
Contributor Author

restran commented Apr 26, 2017

@NoahDragon Please review.

@NoahDragon NoahDragon merged commit 1bb19c8 into hexojs:master Apr 26, 2017
@NoahDragon
Copy link
Member

LGTM. Thanks for the contribution.

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.

3 participants