Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/ci
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ build() {
with_build_env 'make docs threads=1'
;;
*)
with_build_env 'make crystal primitives_spec std_spec compiler_spec docs threads=1 junit_output=.junit/spec.xml DOCS_OPTIONS="--json-config-url=/api/versions.json --canonical-base-url=https://crystal-lang.org/api/latest/"'
with_build_env 'make crystal primitives_spec std_spec compiler_spec docs threads=1 junit_output=.junit/spec.xml DOCS_OPTIONS="--json-config-url=/api/versions.json --canonical-base-url=https://crystal-lang.org/api/latest/ --404-base-href=/api/"'
;;
esac

Expand Down
4 changes: 4 additions & 0 deletions src/compiler/crystal/command/docs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class Crystal::Command
project_info.canonical_base_url = value
end

opts.on("--404-base-href=PATH", %(Set the base href tag on the 404 page - needed for finding assets)) do |value|
project_info.page_404_base_href = value
end

opts.on("--sitemap-base-url=URL", "-b URL", "Set the sitemap base URL and generates sitemap") do |value|
sitemap_base_url = value
end
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/tools/doc/generator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ class Crystal::Doc::Generator
raw_body = read_readme
body = doc(program_type, raw_body)

File.write File.join(@output_dir, "index.html"), MainTemplate.new(body, types, project_info)
File.write File.join(@output_dir, "index.html"), MainTemplate.new(body, types, project_info, nil)

main_index = Main.new(raw_body, Type.new(self, @program), project_info)
File.write File.join(@output_dir, "index.json"), main_index
File.write File.join(@output_dir, "search-index.js"), main_index.to_jsonp

File.write File.join(@output_dir, "404.html"), MainTemplate.new(Error404Template.new.to_s, types, project_info)
File.write File.join(@output_dir, "404.html"), MainTemplate.new(Error404Template.new.to_s, types, project_info, :page_404)
end

def generate_sitemap(types)
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/crystal/tools/doc/html/main.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<% if page_type == :page_404 && base_href = project_info.page_404_base_href %>

Check failure on line 4 in src/compiler/crystal/tools/doc/html/main.html

View workflow job for this annotation

GitHub Actions / x86_64-windows-release / build

unexpected token: "="
<base href="<%= base_href %>" />
<% end %>
<%= HeadTemplate.new(project_info, nil) %>
<meta name="repository-name" content="<%= project_info.name %>">
<title><%= project_info.name %> <%= project_info.version %></title>
Expand Down
1 change: 1 addition & 0 deletions src/compiler/crystal/tools/doc/project_info.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Crystal::Doc
property refname : String? = nil
property source_url_pattern : String? = nil
property canonical_base_url : String? = nil
property page_404_base_href : String? = nil

def initialize(@name : String? = nil, @version : String? = nil, @refname : String? = nil, @source_url_pattern : String? = nil)
end
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/tools/doc/templates.cr
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module Crystal::Doc
ECR.def_to_s "#{__DIR__}/html/_other_types.html"
end

record MainTemplate, body : String, types : Array(Type), project_info : ProjectInfo do
record MainTemplate, body : String, types : Array(Type), project_info : ProjectInfo, page_type : Symbol? do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: at this point this would be more readable as a struct (no action required though)

ECR.def_to_s "#{__DIR__}/html/main.html"
end

Expand Down
Loading