Search code examples
github-pages

Github Pages error: yaml file query returns an empty file


I have a static website repo hosted with Github Pages. The javascript must load two text files (.yml files more precisely) stored in that same repo in a data folder. The functions used to load the two files are the following:

async function readTextFile(path) {
    console.log("Path:", path);
    const response = await fetch(path);
    console.log("Response:", response);
    const text = await response.text();
    console.log("Text:", text);
    return text;
}
export async function loadBodiesData() {
    const content = await readTextFile("./data/kspbodies.yml");
    /* Some post processing */
}
export async function loadConfig() {
    const content = await readTextFile("./data/settings.yml");
    /* Some post processing */
}

The kspbodies.yml file is correctly loaded and its content displayed in the console (Text: ...). The settings.yml file however appears to be empty (Text: <empty string>). The file exists as a direct look at this file from its URL doesn't throw a 404 error, but returns an empty file (0 byte size).

What I have tried

  • Waiting for several hours in case it was needed for all files to be "detected"
  • Renaming settings.yml into something else
  • Creating a new file with the same content as settings.yml, its URL returns an empty file as well

Note: The website works perfectly on a local server.

Does anyone know where this problem comes from and how to fix it ?

Thanks in advance.


Solution

  • Alright I found the problem. It actually comes from the syntax used in the yaml files. The first characters in the file seem to matter. I experimented with the content of a YAML file and here are the results when loaded through the hosted github page:

    • Simplest content: loads correctly
    test: 42
    
    ---
    test: 42
    ...
    
    • Added a comment before the ---: loads correctly
    # Test file
    ---
    test: 42
    ...
    

    So it seems that having a YAML file starting with --- makes the content of the file being ignored by the server. There is probably a difference in syntax standards used between github servers and vscode live server for yaml files.