Jekyll parses any dash-separated numeric filename as date #5603

Closed
marios-zindilis opened this Issue Nov 25, 2016 · 3 comments

Comments

Projects
None yet
4 participants
@marios-zindilis

marios-zindilis commented Nov 25, 2016


  • I am on Debian/Ubuntu GNU/Linux

  • I was trying to build.

My Reproduction Steps

  1. Create a collection, set default layout to page, e.g:

    collections:
      docs:
        output: true
    
  2. Create a file in the collection with a dash-separated filename in which the first three fields are numeric, e.g:

    84093135-42842323-42000001-b890-136270f7e5f1.md
    
  3. Try to build.

The Output I Wanted

  1. Don't parse filenames as dates outside of the posts type scope.
  2. Build 84093135-42842323-42000001-b890-136270f7e5f1.html

The Output I Got

ERROR: YOUR SITE COULD NOT BE BUILT:
------------------------------------
    Invalid date '84093135-42842323-42000001': Document '_m/work/84093135-42842323-42000001-b890-136270f7e5f1.md' does not have a valid date in the filename.

Notes

  • Tested on Jekyll 3.3.1 and 3.0.1, the result is the same.
  • If I change one of the characters in the first three fields (separated by -) in the filename to a letter, the site builds.
  • If I add a date in the frontmatter the site builds, however this collection has no use for dates.
  • The result is the same with error_mode set to strict, warn or lax.

Workaround

  • The files in this collection are generated automatically by a service. I could get the other service to strip the dashes from the filename, and set the permalink in the frontmatter so that the rendered file ends up where it is supposed to end up (with the dashes), but this removes some of the semantics.
@parkr

This comment has been minimized.

Show comment
Hide comment
@parkr

parkr Nov 29, 2016

Member

You're right! This is caused by an overzealous matcher in document.rb.

It shouldn't be \d+ in all those cases, but should be \d{4}-\d{2}-\d{2} so it's YYYY-MM-DD.

Member

parkr commented Nov 29, 2016

You're right! This is caused by an overzealous matcher in document.rb.

It shouldn't be \d+ in all those cases, but should be \d{4}-\d{2}-\d{2} so it's YYYY-MM-DD.

@parkr parkr added the bug label Nov 29, 2016

@oe

This comment has been minimized.

Show comment
Hide comment
@oe

oe Nov 29, 2016

Member

i'll get on that in a bit!

Member

oe commented Nov 29, 2016

i'll get on that in a bit!

@mrexodia

This comment has been minimized.

Show comment
Hide comment
@mrexodia

mrexodia Mar 18, 2017

This recently screwed me pretty badly because I have always been ignoring the manual and using DD-MM-YYYY as a date format which worked perfectly fine until now.

C# script to fix up the directory:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace jekyllfuckup
{
    class Program
    {
        static void Main(string[] args)
        {
            var files = Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.md").ToArray();
            foreach(var filepath in files)
            {
                var filename = Path.GetFileName(filepath);
                var dd = filename.Substring(0, 2);
                var mm = filename.Substring(3, 2);
                var yyyy = filename.Substring(6, 4);
                try
                {
                    var x = int.Parse(dd) + int.Parse(mm) + int.Parse(yyyy);
                    var name = filename.Substring(10);
                    var newfile = Path.Combine(Path.GetDirectoryName(filepath), $"{yyyy}-{mm}-{dd}{name}");
                    File.Move(filepath, newfile);
                }
                catch { }
            }
        }
    }
}

mrexodia commented Mar 18, 2017

This recently screwed me pretty badly because I have always been ignoring the manual and using DD-MM-YYYY as a date format which worked perfectly fine until now.

C# script to fix up the directory:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace jekyllfuckup
{
    class Program
    {
        static void Main(string[] args)
        {
            var files = Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.md").ToArray();
            foreach(var filepath in files)
            {
                var filename = Path.GetFileName(filepath);
                var dd = filename.Substring(0, 2);
                var mm = filename.Substring(3, 2);
                var yyyy = filename.Substring(6, 4);
                try
                {
                    var x = int.Parse(dd) + int.Parse(mm) + int.Parse(yyyy);
                    var name = filename.Substring(10);
                    var newfile = Path.Combine(Path.GetDirectoryName(filepath), $"{yyyy}-{mm}-{dd}{name}");
                    File.Move(filepath, newfile);
                }
                catch { }
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment