-
Notifications
You must be signed in to change notification settings - Fork 15
Better sidebar/navbar rendering from the Documenter end #278
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
base: master
Are you sure you want to change the base?
Changes from all commits
7ae730d
ba5ebb1
f2e1c8f
5532dcd
38d8d30
74aa593
480267f
9d26d5f
0f7b666
944cf2b
e2a972f
15b538f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,45 @@ using DocumenterCitations | |
using DocumenterInterLinks | ||
using LaTeXStrings | ||
|
||
struct DecomposeInSidebar | ||
path::String | ||
pages::Any | ||
end | ||
|
||
# So you can only really pull this trick once in a Julia session | ||
# But because doc.user.pages is a Vector{Any}, we can't really do anything about it. | ||
function DocumenterVitepress.pagelist2str(doc, ds::Vector{<: Any}, ::Val{:sidebar}) | ||
println("Hello World!!!") | ||
if !all(x -> x isa DecomposeInSidebar, ds) | ||
# if this is false, invoke the default method. | ||
return invoke(pagelist2str, Tuple{Any, Any, Val{:sidebar}}, doc, ds, Val(:sidebar)) | ||
end | ||
contents = DocumenterVitepress.pagelist2str.((doc,), ds, (Val(:sidebar),)) | ||
ret = "{\n" * join(contents, ",\n") * "\n}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest just taking a dep on some JSON package rather than having this brittle manual construction code, it's easy to mess up escaping etc. |
||
println(ret) | ||
return ret | ||
end | ||
|
||
function DocumenterVitepress.pagelist2str(doc, ds::DecomposeInSidebar, ::Val{:sidebar}) | ||
raw_contents = DocumenterVitepress.pagelist2str(doc, ds.pages, Val(:sidebar)) | ||
contents = if raw_contents isa String | ||
raw_contents | ||
else | ||
join(raw_contents, ",\n") | ||
end | ||
|
||
return "\"/$(ds.path)/\": {\n$(contents)\n}" | ||
end | ||
|
||
function DocumenterVitepress.pagelist2str(doc, ds::DecomposeInSidebar, ::Val{:navbar}) | ||
return DocumenterVitepress.pagelist2str(doc, ds.pages, Val(:sidebar)) | ||
end | ||
|
||
function Documenter.walk_navpages(ds::DecomposeInSidebar, parent, doc) | ||
return Documenter.walk_navpages(ds.pages, parent, doc) | ||
end | ||
|
||
|
||
# Handle DocumenterCitations integration - if you're running this, then you don't need anything here!! | ||
documenter_citations_dir = dirname(dirname(pathof(DocumenterCitations))) | ||
documenter_citations_docs_dir = joinpath(documenter_citations_dir, "docs") | ||
|
@@ -53,7 +92,7 @@ makedocs(; | |
source = "src", | ||
build = "build", | ||
pages = [ | ||
"Manual" => [ | ||
DecomposeInSidebar("manual", "Manual" => [ | ||
"Get Started" => "manual/get_started.md", | ||
"Updating to DocumenterVitepress" => "manual/documenter_to_vitepress_docs_example.md", | ||
"Code" => "manual/code_example.md", | ||
|
@@ -63,12 +102,11 @@ makedocs(; | |
"CSS Styling" => "manual/style_css.md", | ||
"Authors' badge" => "manual/author_badge.md", | ||
"GitHub Icon with Stars" => "manual/repo_stars.md", | ||
], | ||
"Developers' documentation" => [ | ||
]), | ||
DecomposeInSidebar("devs", "Developers' documentation" => [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's a nice thing to have, but I don't love the name. I don't feel that it communicates his purpose fully. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it's more a test at this point. We can move this in and refactoring before merge. |
||
"The rendering process" => "devs/render_pipeline.md", | ||
"Internal API" => "devs/internal_api.md", | ||
], | ||
"api.md", | ||
]), | ||
], | ||
plugins = [bib, links], | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# In Vitepress you can only have one frontmatter block. | ||
# But users / other Documenter stages may inject multiple. | ||
# So, we have a stage that will merge and render all frontmatter blocks | ||
# before doing anything else. | ||
|
||
function merge_and_render_frontmatter(io::IO, mime::MIME"text/yaml", page, doc; kwargs...) | ||
frontmatter = String[] | ||
for block in page.mdast.children | ||
element = block.element | ||
if element isa MarkdownAST.CodeBlock && element.info == "@frontmatter" | ||
push!(frontmatter, element.code) | ||
elseif element isa Documenter.RawNode && startswith(element.text, "---") | ||
push!(frontmatter, join(split(element.text, "\n")[2:end-1], "\n")) | ||
end | ||
end | ||
|
||
if haskey(page.globals.meta, :Title) | ||
pushfirst!(frontmatter, "title: \"$(page.globals.meta[:Title])\"") | ||
end | ||
if haskey(page.globals.meta, :Description) | ||
pushfirst!(frontmatter, "description: \"$(page.globals.meta[:Description])\"") | ||
end | ||
println(io, "---") | ||
println(io, join(frontmatter, "\n")) | ||
println(io, "---") | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain what this is supposed to do and why you need the
invoke
? I'm not sure yet if thisDecomposeInSidebar
thing shouldn't work differently, but I'm also not quite getting yet how you intended it