Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is an internal link? #690

Open
jpotier opened this issue Feb 27, 2019 · 8 comments
Open

What is an internal link? #690

jpotier opened this issue Feb 27, 2019 · 8 comments
Labels

Comments

@jpotier
Copy link

jpotier commented Feb 27, 2019

The check --help shows:

Usage: site check [--internal-links]
  Validate the site output

Available options:
  -h,--help                Show this help text
  --internal-links         Check internal links only

If I use this, it seems to skip all links. So I tried to gather some documentation on what an internal link is, without much success. So my question is, what is an internal link?

@jaspervdj
Copy link
Owner

Hey @jpotier, an internal link leads to another page on the same hakyll website. An external link goes to a different domain. Hope this helps!

@jpotier
Copy link
Author

jpotier commented Feb 28, 2019

Hey @jaspervdj this goes along my intuition, but is broken by my experience. If I run check as normal, some internal links are properly detected as broken:

 % site check
Checking file _site/about.html
  [ERROR] Broken link to "./haddock/"
Checking file _site/error.html
Checking file _site/index.html
…

If I run check with flag --internal-links:

 % site check --internal-links
Checking file _site/about.html
Checking file _site/error.html
Checking file _site/index.html
…

It seems internal links are ignored. Hence my question: what is an internal link? What's the exact syntactic requirement for it being internal?

@jpotier
Copy link
Author

jpotier commented Mar 4, 2019

So, I've been through the codebase and I'm still puzzled. I must be missing something obvious. I'll keep looking.

@jaspervdj
Copy link
Owner

The logic is pretty simple (but admittedly I haven't touched this part of the code in a while):
https://github.com/jaspervdj/hakyll/blob/master/lib/Hakyll/Web/Html.hs#L148

@jpotier
Copy link
Author

jpotier commented Mar 5, 2019

I'll try and make a MWE showing the problem. Hopefully I'll bump into what I did wrong first :DD

@jpotier
Copy link
Author

jpotier commented Mar 5, 2019

So, I've got something pretty small that shows my problem:

site.hs:

{-# LANGUAGE OverloadedStrings #-}

import Hakyll

main :: IO ()
main = do
  hakyll $ do
    match "about.md" $ do
        route   $ setExtension "html"
        compile $ pandocCompiler
            >>= loadAndApplyTemplate "templates/default.html" defaultContext

    match "templates/*" $ compile templateBodyCompiler

about.md:

---
  title: Main title
---

Title
-------

Text

[External link](https://www.example.com)

[Internal link (valid)](./about.html)

[Internal link (broken)](./shoe-laces.html)

template/default.html:

<!DOCTYPE html>
<meta charset="UTF-8">
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>MWE - $title$</title>
  </head>
  <body>
    $title$

    $body$
  </body>
</html>

The problem:

$ site check
Checking file _site/about.html
  [ERROR] Broken link to "./shoe-laces.html"

but

$ site check --internal-links
Checking file _site/about.html

No error is displayed. I think it should show an error, since it's an internal link, and it's broken.

Versions:

Dependency base ==4.*: using base-4.12.0.0
Dependency filepath -any: using filepath-1.4.2.1
Dependency hakyll ==4.12.*: using hakyll-4.12.5.1
Dependency pandoc -any: using pandoc-2.6
Using Cabal-2.4.0.1 compiled by ghc-8.6
Using compiler: ghc-8.6.3

@jpotier
Copy link
Author

jpotier commented Mar 22, 2019

@jaspervdj can you reproduce this?

@jaspervdj jaspervdj added the bug label May 31, 2019
@Radvendii
Copy link
Contributor

hakyll/lib/Hakyll/Check.hs

Lines 167 to 175 in 1abdeee

checkUrlIfNeeded :: FilePath -> URL -> MVar CheckerWrite -> Checker ()
checkUrlIfNeeded filepath url m = do
logger <- checkerLogger <$> ask
needsCheck <- (== All) . checkerCheck <$> ask
checked <- (url `Map.member`) <$> get
if not needsCheck || checked
then Logger.debug logger "Already checked, skipping"
else do modify $ Map.insert url m
checkUrl filepath url

It seems like if --internal-links is set, then nothing is checked.

    needsCheck <- (== All) . checkerCheck <$> ask

This line just checks if we're supposed to check all links.

    if not needsCheck || checked
        then Logger.debug logger "Already checked, skipping"
        else do modify $ Map.insert url m
                checkUrl filepath url

And if not, we don't check the link. Regardless of whether it's an internal or external link.

Am I interpreting this code correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants