Code Monkey home page Code Monkey logo

Comments (1)

pocketWashburn avatar pocketWashburn commented on August 20, 2024

I know this one is 9 months old, so if you've already found a fix my apologies. I've been seeing the same problem, and I believe I'm narrowing in on the issue.

The quick solution is to have your slug (file name) be exclusively lower case.

The longer answer has absorbed a number of hours this evening/morning now, but I believe is traced to the fact that the slug only gets passed through strtolower in Post::expected_source_filename(). I believe that this function doesn't get run on new posts before the hook is called, thus the $slug referenced by the hook isn't in lower case, however as part of the Updater process the function does get called leading to the links on the home page being correct but those available to hooks being incorrect.

There are several different possible solutions:

  1. just save your files in all lower case, causing your slug to be in all lower case and this issue to never occur.

  2. modify the Post::array_for_template() function to make $slug lowercase:

public function array_for_template()
    {
        $this->slug = strtolower($this->slug);
        ...
    }

This seems 'hacky' and like its not solving the real issue...

  1. modify Post::__construct so that $this->slug is set to lowercase at that time, making it no longer necessary to set it to lower case in Post::expected_source_filename():
public function __construct($source_filename, $is_draft = -1 /* auto */)
    {
        ...
        if (is_numeric($filename_datestr)) {
            ...
            $this->slug = strtolower(ltrim(substr($filename, 11, -(strlen(Updater::$post_extension))), '-'));
        } else {
            ...
            $this->slug = strtolower(substring_before($filename, '.'));
        }
    }

This seems less 'hacky' to me, but I'm not clear if there was a reason for waiting to make the slug lowercase until Post::expected_source_filename()

  1. Figure out why its only an issue for the array_for_template() call thats part of the hook process, and not for the normal post updating/creating that gets done for the rest of the blog.

I'm leaning towards option number 3, and after I get some sleep I'll test it further to see if it breaks anything, and possibly submit a pull request with the change to see what Marco thinks (assuming he has time/interest).

from secondcrack.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.