janl / mustache.js

Minimal templating with {{mustaches}} in JavaScript
https://mustache.github.io
MIT License
16.47k stars 2.39k forks source link

Templates aren't working in gh-pages site #726

Open jakkrobbit opened 5 years ago

jakkrobbit commented 5 years ago

I set up a page for a forked repo here. The site's supposed to load text on the right side, but as you can see, there's just a message saying "Your browser doesn't currently support JavaScript". It's set up to render text from .mst files located in dist/scripts/templates.

It works fine on the original site and when I'm working on localhost, but I get 404 errors when testing the gh-pages version. And despite what the error message says, the rest of the Javascript works fine - tooltips, switching tabs, and saving files are all functioning. Compiling mustache templates is literally the only thing that isn't working.

If it helps, here's the block of code related to mustache:

// Variable Setup
var quench_options = {
    'basic-gulpfile': false,
    'proj-name': 'Quench',
    'version': '1.0.0',
    'descrp': 'A Gulp file and project generator.',
    'author': 'Quench',
    'browser-sync': true,
    'css': true,
    'css-autoprefix': true,
    'css-destination': "dist/styles",
    'css-minimize': false,
    'css-precompile': true,
    'css-precompile-type': "sass",
    'css-source': "src/styles",
    'gulp-sass': true,
    'images-destination': "dist/images",
    'images-optimize': true,
    'images-source': "src/images",
    'js': true,
    'js-coffeescript': false,
    'js-concatenate': true,
    'js-destination': "dist/scripts",
    'js-es6': false,
    'es-lint': false,
    'js-minimize': true,
    'js-source': "src/scripts",
    'usingBS': true
};

// File Handlers
function displayFile(file) {
    'use strict';
    $('#file').html(file);
    hljs.highlightBlock($('#file').get(0));
}

function renderFile(file, renderOnly) {
    'use strict';
    var pJSON = '';

    if (renderOnly === undefined) {
        renderOnly = false;
    }

    if (!renderOnly) {
        $('#file-wrapper').addClass('loading');
    }

    if ($('#template-' + file.replace('.', '')).length) {
        var template = $('#template-' + file.replace('.', '')).text();
        Mustache.parse(template);
        pJSON = Mustache.render(template, quench_options);
        if (!renderOnly) {
            displayFile(pJSON);
            $('#file-wrapper').removeClass('loading');
        }
        return pJSON;
    } else {
        $.ajax({
            url: '/dist/scripts/templates/' + file + '.mst',
            dataType: 'text',
            success: function (template) {
                //Save template
                $('<script>')
                    .attr('type', 'x-tmpl-mustache')
                    .attr('id', 'template-' + file.replace('.', ''))
                    .text(template)
                    .appendTo('body');

                pJSON = Mustache.render(template, quench_options);
                if (!renderOnly) {
                    displayFile(pJSON);
                    $('#file-wrapper').removeClass('loading');
                }
                return pJSON;
            }
        });
    }
}
jakkrobbit commented 5 years ago

So, I was able to circumvent the issue by moving the templates file to the root directory. I'm still wondering why the mustache templates were the only files in the dist folder that weren't working.