簡體   English   中英

將Javascript配置文件用於車把博客模板,但配置無法正常工作

[英]Using a javascript config file for a handlebars blog template but config isn't working correctly

我正在嘗試為正在處理的博客主題添加配置文件。 使用主題的任何人都可以在一個地方輸入變量(即:disqus短名稱,google Analytics(分析)UA代碼等)。 我已經完成了所有工作,但是由於某種原因,它似乎並未加載配置文件。 這是我所擁有的:

我在theme-name / assets / js文件夾中的一個名為“ ichi-config.js”的文件中擁有此文件:

// If you use DisQus comments, add your disqus shortname here
var config_disqus_shortname = 'barneycarney';

這是我在theme-name / assets / js文件夾中名為“ disqus.js”的文件中包含的javascript,如果他們在配置文件中輸入了短名稱,則會加載注釋部分:

var disqus_loaded = false;

function load_disqus() {
    if (config_disqus_shortname !== '') {
        disqus_loaded = true;
        var disqus_shortname = config_disqus_shortname;
        var disqus_identifier = '{{post.id}}'; // make sure to use the post.id as an identifier, otherwise disqus will use the pages url per default, which might be problematic...

        // For embedding disqus under a post
        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
    }
}

load_disqus();

然后,在主題根文件夾中的“ post.hbs”文件中,我有:

<div id="disqus_thread"></div>
<script src="{{asset "js/disqus.js"}}"></script>

在“ default.hbs”文件的頭部(基本上是所有博客頁面的模板)中,我嘗試加載“ ichi-config.js”腳本:

<script type="text/javascript" src="{{asset "js/ichi-config.js"}}"></script>

我已經經歷了一百萬遍了,我正在拔頭發以使其正常工作。 提前致謝! 如果要查看存儲庫,可以在以下位置找到它:

https://github.com/Bernjc/ichi/tree/feature/theme-config

我設法解決了。 這一定是長時間的編碼前的夜晚,但是當我設置了config_disqus_shortname變量本來,我是有作為config-disqus-shortname這是造成問題。 現在就像魅力一樣!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM