RFC 1590: [2.x] Dynamic Markdown links

Details

Author: Caen De Silva (@caendesilva)
·

Abstract

Dynamic Markdown Links

PR Abstract

Based on RFC 1590 proposed in https://twitter.com/CodeWithCaen/status/1761810371063497098

Overview

HydePHP provides a powerful feature for automatically converting Markdown links to source files to the corresponding routes in the built site.

This allows for much better writing experience when using an IDE, as you can easily navigate to the source file by clicking on the link.

Usage

Using the feature is simple: Just use source file paths for links:

[Home](/_pages/index.blade.php)
![Logo](/_media/logo.svg)

As you can see, it works for both pages and media assets. The leading slash is optional and will be ignored by Hyde, but including it often gives better IDE support.

Behind the Scenes

During the build process, HydePHP converts source paths to their corresponding routes, and evaluates them depending on the page being rendered.

If your page is in the site root then:

  • /_pages/index.blade.php becomes index.html
  • /_media/logo.svg becomes media/logo.svg

If your page is in a subdirectory then:

  • /_pages/index.blade.php becomes ../index.html
  • /_media/logo.svg becomes ../media/logo.svg

Of course, if your page is in a more deeply nested directory, the number of ../ will increase accordingly.

We will of course also match your configured preference for pretty_urls and only include the .html extension when desired.

Limitations

There are some limitations and considerations to keep in mind when using this feature:

  • This feature won't work for dynamic routes (not backed by a file)
  • If you rename a file, links will break. Your IDE may warn about this.
  • If a file is not found, we won't be able to see it when evaluating links.
  • Relative links are not supported (so ../_pages/index.blade.php won't work)