Skip to content

Commit

Permalink
Refactor next_font helper & NexT.utils.loadComments
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Jul 23, 2020
1 parent bfa9a75 commit e953cbf
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion layout/_third-party/comments/changyan.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<script id="cy_cmt_num" src="https://changyan.sohu.com/upload/plugins/plugins.list.count.js?clientId={{ theme.changyan.appid }}"></script>
{% elif page.comments %}
<script>
NexT.utils.loadComments(document.querySelector('#SOHUCS'), () => {
NexT.utils.loadComments('#SOHUCS', () => {
NexT.utils.getScript('https://changyan.sohu.com/upload/changyan.js', () => {
window.changyan.api.config({
appid: '{{ theme.changyan.appid }}',
Expand Down
2 changes: 1 addition & 1 deletion layout/_third-party/comments/disqus.njk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
this.language = '{{ __('disqus') }}';
{% endif -%}
};
NexT.utils.loadComments(document.querySelector('#disqus_thread'), () => {
NexT.utils.loadComments('#disqus_thread', () => {
if (window.DISQUS) {
DISQUS.reset({
reload: true,
Expand Down
2 changes: 1 addition & 1 deletion layout/_third-party/comments/disqusjs.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{%- set disqusjs_js_uri = theme.vendors.disqusjs_js or '//cdn.jsdelivr.net/npm/disqusjs@1/dist/disqus.js' %}

<script>
NexT.utils.loadComments(document.querySelector('#disqus_thread'), () => {
NexT.utils.loadComments('#disqus_thread', () => {
NexT.utils.getScript('{{ url_for(disqusjs_js_uri) }}', () => {
window.dsqjs = new DisqusJS({
api : '{{ theme.disqusjs.api }}' || 'https://disqus.com/api/',
Expand Down
2 changes: 1 addition & 1 deletion layout/_third-party/comments/gitalk.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{%- set gitalk_js_uri = theme.vendors.gitalk_js or '//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js' %}

<script>
NexT.utils.loadComments(document.querySelector('#gitalk-container'), () => {
NexT.utils.loadComments('#gitalk-container', () => {
NexT.utils.getScript('{{ url_for(gitalk_js_uri) }}', () => {
var gitalk = new Gitalk({
clientID : '{{ theme.gitalk.client_id }}',
Expand Down
2 changes: 1 addition & 1 deletion layout/_third-party/comments/livere.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{%- if page.comments %}
<script>
NexT.utils.loadComments(document.querySelector('#lv-container'), () => {
NexT.utils.loadComments('#lv-container', () => {
window.livereOptions = {
refer: location.pathname.replace(CONFIG.root, '').replace('index.html', '')
};
Expand Down
2 changes: 1 addition & 1 deletion layout/_third-party/comments/valine.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- set valine_uri = theme.vendors.valine or '//cdn.jsdelivr.net/npm/valine@1/dist/Valine.min.js' %}

<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
NexT.utils.loadComments('#valine-comments', () => {
NexT.utils.getScript('{{ url_for(valine_uri) }}', () => {
new Valine(Object.assign({
el : '#valine-comments',
Expand Down
9 changes: 5 additions & 4 deletions scripts/helpers/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ hexo.extend.helper.register('next_font', function() {
const fontHost = config.host || '//fonts.googleapis.com';

// Get a font list from config
let fontFamilies = ['global', 'title', 'headings', 'posts', 'codes'].map(item => {
let fontFamilies = [];
['global', 'title', 'headings', 'posts', 'codes'].forEach(item => {
if (config[item] && config[item].family && config[item].external) {
return config[item].family + fontStyles;
fontFamilies = fontFamilies.concat(config[item].family.split(','));
}
return '';
}).filter(item => item !== '');
});

fontFamilies = fontFamilies.map(name => name.trim() + fontStyles);
fontFamilies = [...new Set(fontFamilies)].join('|');

// Merge extra parameters to the final processed font string
Expand Down
2 changes: 1 addition & 1 deletion source/css/_variables/base.styl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ $menu-item-bg-color-dark = $black-light;
// --------------------------------------------------
get_font_family(config) {
$custom-family = hexo-config('font.' + config + '.family');
return $custom-family is a 'string' ? $custom-family : null;
return $custom-family is a 'string' ? unquote($custom-family) : null;
}

// Font families.
Expand Down
3 changes: 2 additions & 1 deletion source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ NexT.utils = {
}
},

loadComments: function(element, callback) {
loadComments: function(selector, callback) {
const element = document.querySelector(selector);
if (!CONFIG.comments.lazyload || !element) {
callback();
return;
Expand Down

1 comment on commit e953cbf

@stevenjoezhang
Copy link
Member Author

Choose a reason for hiding this comment

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

Please sign in to comment.