MyNixOS website logo
Description

Use shortcut-links in markdown file for Hakyll.

Use shortcut-links in markdown file for Hakyll. See README for more details.

hakyll-shortcut-links

scissors GitHub CI Hackage MPL-2.0 license

This library adds the support of the shortcut-links library in the static website generator library — Hakyll.

That being said, it means that you can use shortcuts from shortcut-links library or custom ones in your markdown files which would be extended into complete URLs during the Hakyll site compilation process.

Here is the example of how links could look like before expansion:

Here is going to be a link to the [hakyll-shortcut-links](@hackage) library on Hackage.
And another link to the [GitHub sources](@github(kowainik):hakyll-shortcut-links).

which is going to be transformed into the ordinary links automatically by the library functions:

Here is going to be a link to the [hakyll-shortcut-links](http://hackage.haskell.org/package/hakyll-shortcut-links) library on Hackage.
And another link to the [GitHub sources](https://github.com/kowainik/hakyll-shortcut-links).

For the full list of the supported shortcuts, you can check ShortcutLinks.All module of the shortcut-links library.

How to use in a Hakyll project

To use hakyll-shortcut-links in your ready Hakyll project, you would need to go through the following steps:

Add the dependency

Add hakyll-shortcut-links under the build-depends section in your .cabal file. If you use Stack build tool, you would need to add the library into extra-deps list in the stack.yaml file.

Change a standard pandocCompiler

Here we assume that you already have a Hakyll project. If not then you can use these tutorials to create one. Anyway, you would eventually have the code that uses pandocCompiler that could look like this function:

compile $
    pandocCompiler >>= loadAndApplyTemplate "templates/post.html" postCtx

All you need to change is to use allShortcutLinksCompiler or shortcutLinksCompiler function from this library instead of the standard pandocCompiler:

import Hakyll.ShortcutLinks (allShortcutLinksCompiler)

...

compile $
    allShortcutLinksCompiler >>= loadAndApplyTemplate "templates/post.html" postCtx

That's all!

There could be another situation. You could already have some custom Compiler function:

-- | A pandoc compiler which makes all entries of "42" bold automatically.
bold42Compiler :: Compiler (Item String)
bold42Compiler = pandocCompilerWithTransform
    myHakyllReaderOptions
    myHakyllWriterOptions
    make42Bold

In this case, you can use the applyAllShortcuts function directly. All you need is to combine two transformations:

myCompiler :: Compiler (Item String)
myCompiler = pandocCompilerWithTransformM
    myHakyllReaderOptions
    myHakyllWriterOptions
    (applyAllShortcuts . make42Bold)

Use shortcuts in your docs

The hardest part is done, now you can create links using the shortcuts, and the Hakyll is going to build full URLs for them. Happy coding!

Example

Here is an example of the pull request that introduces the hakyll-shortcut-links library into the scope:

As you can see by the diff the only actual change needed for that was replacing pandocCompiler with allShortcutLinksCompiler.

Examples of the @github shortcut:

  • Link to a user :

    ShortcutPlain markdown
    [foo](@github)[foo](https://github.com/foo)
    [foo Github profile](@github(foo))[foo Github profile](https://github.com/foo)
  • Link to a repository :

    ShortcutPlain markdown
    [bar](@github:foo)[bar](https://github.com/foo/bar)
    [Github Source](@github(foo):bar)[Github Source](https://github.com/foo/bar)

Acknowledgement

Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY.

Metadata

Version

0.1.0.2

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows