Skip to content

Commit

Permalink
Check links inside the bibliography
Browse files Browse the repository at this point in the history
  • Loading branch information
goerz committed Nov 3, 2023
1 parent 426a649 commit d0c91de
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 3 deletions.
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [Unreleased][]

### Fixed

* Calling `makedocs` with `linkcheck=true` now also checks links (e.g., DOIs) inside the bibliography. [[#58][]]


## [Version 1.3.1][1.3.1] - 2023-11-02

### Fixed
Expand Down Expand Up @@ -143,6 +150,7 @@ There were several bugs and limitations in version `1.2.x` for which some existi
[1.0.0]: https://github.com/JuliaDocs/DocumenterCitations.jl/compare/v0.2.12...v1.0.0
[#61]: https://github.com/JuliaDocs/DocumenterCitations.jl/pull/61
[#59]: https://github.com/JuliaDocs/DocumenterCitations.jl/issues/59
[#58]: https://github.com/JuliaDocs/DocumenterCitations.jl/issues/58
[#56]: https://github.com/JuliaDocs/DocumenterCitations.jl/pull/56
[#53]: https://github.com/JuliaDocs/DocumenterCitations.jl/issues/53
[#42]: https://github.com/JuliaDocs/DocumenterCitations.jl/pull/42
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DocumenterCitations"
uuid = "daee34ce-89f3-4625-b898-19384cb65244"
authors = ["Michael Goerz <[email protected]>"]
version = "1.3.1"
version = "1.3.2-dev"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
4 changes: 2 additions & 2 deletions docs/src/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ @mastersthesis{GoerzDiploma2010
Title = {Optimization of a Controlled Phasegate for Ultracold Calcium Atoms in an Optical Lattice},
School = {Freie Universität Berlin},
type = {{Diplomarbeit}},
url = {http://michaelgoerz.net/research/diploma_thesis.pdf},
url = {https://michaelgoerz.net/research/diploma_thesis.pdf},
Year = {2010},
}

Expand Down Expand Up @@ -427,7 +427,7 @@ @incollection{TannorBookChapter1991
pages = {333--345},
publisher = {Springer},
title = {Design of Femtosecond Pulse Sequences to Control Photochemical Products},
doi = {0.1007/978-94-011-2642-7_23},
doi = {10.1007/978-94-011-2642-7_23},
year = {1991},
}

Expand Down
14 changes: 14 additions & 0 deletions src/bibliography_node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,17 @@ function Documenter.LaTeXWriter.latex(
println(io, "}% end @bibliography")

end


function Documenter.linkcheck(
node::MarkdownAST.Node,
bibliography::BibliographyNode,
doc::Documenter.Document
)
success = true
for item in bibliography.items
success &= !(Documenter.linkcheck(item.reference, doc) === false)
# `linkcheck` may return `true` / `false` / `nothing`
end
return success
end
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ using DocumenterCitations
include("test_undefined_citations.jl")
end

println("\n* test link checking (test_linkcheck.jl):")
@time @safetestset "linkcheck" begin
include("test_linkcheck.jl")
end

print("\n")

end
Expand Down
44 changes: 44 additions & 0 deletions test/test_linkcheck.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using DocumenterCitations
using Test
using TestingUtilities: @Test # much better at comparing strings
using IOCapture: IOCapture

include("run_makedocs.jl")


@testset "Check invalid url in .bib file " begin

# https://github.com/JuliaDocs/DocumenterCitations.jl/issues/58

root = splitext(@__FILE__)[1]

bib = CitationBibliography(joinpath(root, "src", "invalidlink.bib"), style=:numeric)

run_makedocs(
root;
linkcheck=true,
sitename="Test",
plugins=[bib],
pages=["Home" => "index.md", "References" => "references.md",],
check_failure=true
) do dir, result, success, backtrace, output

@test !success
@test contains(output, r"Error:.*http://www.invalid-server.doesnotexist/page.html")
@test contains(
output,
"Error: linkcheck 'http://httpbin.org/status/404' status: 404."
)
@test contains(
output,
"Error: linkcheck 'http://httpbin.org/status/500' status: 500."
)
@test contains(
output,
"Error: linkcheck 'http://httpbin.org/status/403' status: 403."
)
@test contains(result.msg, "`makedocs` encountered an error [:linkcheck]")

end

end
8 changes: 8 additions & 0 deletions test/test_linkcheck/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Testing link checks for broken links


## Problem description

The `linkcheck` option for `makedocs` should complain about [broken links](http://httpbin.org/status/403).

Ref [GoerzPhd2015](@cite) contains broken links.
8 changes: 8 additions & 0 deletions test/test_linkcheck/src/invalidlink.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@phdthesis{GoerzPhd2015,
Author = {Goerz, Michael},
Title = {Optimizing Robust Quantum Gates in Open Quantum Systems},
School = {Universität Kassel},
url = {http://www.invalid-server.doesnotexist/page.html},
Year = {2015},
note = {See \url{http://httpbin.org/status/404} for additional formats. Source available on \href{http://httpbin.org/status/500}{Github}},
}
4 changes: 4 additions & 0 deletions test/test_linkcheck/src/references.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## References

```@bibliography
```

0 comments on commit d0c91de

Please sign in to comment.