Skip to content

Commit eb4f9c2

Browse files
committed
favicon
1 parent 30f22d0 commit eb4f9c2

File tree

6 files changed

+50
-23
lines changed

6 files changed

+50
-23
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ JSON = "0.21"
3333
JSON2 = "0.3"
3434
MD5 = "0.2"
3535
PlotlyBase = "0.8.5, 0.8.6"
36-
julia = "1.3"
3736
YAML = "0.4.7"
37+
julia = "1.3"
3838

3939
[extras]
4040
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/favicon.ico

15 KB
Binary file not shown.

src/handler/index_page.jl

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
function resource_url(app::DashApp, resource::AppRelativeResource)
1+
function resource_url(app::DashApp, resource::AppRelativeResource)
22
prefix = get_setting(app, :requests_pathname_prefix)
33
return string(prefix,
44
"_dash-component-suites/",
55
resource.namespace,
66
"/",
7-
build_fingerprint(resource.relative_path, resource.version, resource.ts)
7+
build_fingerprint(resource.relative_path, resource.version, resource.ts)
88
)
99
end
1010

@@ -19,7 +19,7 @@ function asset_path(app::DashApp, path::AbstractString)
1919
end
2020

2121
resource_url(app::DashApp, resource::AppExternalResource) = resource.url
22-
function resource_url(app::DashApp, resource::AppAssetResource)
22+
function resource_url(app::DashApp, resource::AppAssetResource)
2323
return string(
2424
asset_path(app, resource.path),
2525
"?m=", resource.ts
@@ -42,7 +42,7 @@ function metas_html(app::DashApp)
4242
get(tag, "http-equiv", "") == "X-UA-Compatible"
4343
end
4444
has_charset = any(tag -> haskey(tag, "charset"), meta_tags)
45-
45+
4646
result = String[]
4747
!has_ie_compat && push!(result, "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">")
4848
!has_charset && push!(result, "<meta charset=\"UTF-8\">")
@@ -52,7 +52,7 @@ function metas_html(app::DashApp)
5252

5353
end
5454

55-
function css_html(app::DashApp, resources::ApplicationResources)
55+
function css_html(app::DashApp, resources::ApplicationResources)
5656
join(
5757
make_css_tag.(Ref(app), resources.css), "\n "
5858
)
@@ -77,7 +77,7 @@ app_entry_html() = """
7777
</div>
7878
"""
7979

80-
function config_html(app::DashApp)
80+
function config_html(app::DashApp)
8181
config = Dict{Symbol, Any}(
8282
:url_base_pathname => get_setting(app, :url_base_pathname),
8383
:requests_pathname_prefix => get_setting(app, :requests_pathname_prefix),
@@ -94,20 +94,35 @@ function config_html(app::DashApp)
9494
)
9595
end
9696
return """<script id="_dash-config" type="application/json">$(JSON2.write(config))</script>"""
97-
end
97+
end
9898

9999

100100
renderer_html() = """<script id="_dash-renderer" type="application/javascript">var renderer = new DashRenderer();</script>"""
101101

102-
favicon_html(app::DashApp) = ""
102+
function favicon_html(app::DashApp, resources::ApplicationResources)
103+
favicon_url = if !isnothing(resources.favicon)
104+
asset_path(app, resources.favicon.path)
105+
else
106+
"$(get_setting(app, :requests_pathname_prefix))_favicon.ico?v=$(build_info().dash_version)"
107+
end
108+
return format_tag(
109+
"link",
110+
Dict(
111+
"rel" => "icon",
112+
"type" => "image/x-icon",
113+
"href" => favicon_url
114+
),
115+
opened = true
116+
)
117+
end
118+
103119

120+
function index_page(app::DashApp, resources::ApplicationResources)
104121

105-
function index_page(app::DashApp, resources::ApplicationResources)
106-
107122
result = interpolate_string(app.index_string,
108123
metas = metas_html(app),
109124
title = app.title,
110-
favicon = favicon_html(app),
125+
favicon = favicon_html(app, resources),
111126
css = css_html(app, resources),
112127
app_entry = app_entry_html(),
113128
config = config_html(app),
@@ -121,7 +136,7 @@ function index_page(app::DashApp, resources::ApplicationResources)
121136
"#_dash_config" => r"id=\"_dash-config\"",
122137
"dash-renderer" => r"src=\"[^\"]*dash[-_]renderer[^\"]*\"",
123138
"new DashRenderer" => r"id=\"_dash-renderer",
124-
]
139+
]
125140
)
126141
return result
127142
end

src/handler/make_handler.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ include("processors/index.jl")
55
include("processors/layout.jl")
66
include("processors/reload_hash.jl")
77
include("processors/resource.jl")
8+
include("processors/default_favicon.jl")
89

910
function start_reload_poll(state::HandlerState)
1011
folders = Set{String}()
@@ -124,6 +125,7 @@ function make_handler(app::DashApp, registry::ResourcesRegistry; check_layout =
124125
add_route!(process_layout, router, "$(prefix)_dash-layout")
125126
add_route!(process_dependencies, router, "$(prefix)_dash-dependencies")
126127
add_route!(process_reload_hash, router, "$(prefix)_reload-hash")
128+
add_route!(process_default_favicon, router, "$(prefix)_favicon.ico")
127129
add_route!(process_resource, router, "$(prefix)_dash-component-suites/<namespace>/<path>")
128130
add_route!(process_assets, router, "$(prefix)$(assets_url_path)/<file_path>")
129131
add_route!(process_callback, router, "POST", "$(prefix)_dash-update-component")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function process_default_favicon(request::HTTP.Request, state::HandlerState)
2+
ico_contents = read(
3+
joinpath(ROOT_PATH, "src", "favicon.ico")
4+
)
5+
return HTTP.Response(
6+
200,
7+
["Content-Type" => "image/x-icon"],
8+
body = ico_contents
9+
)
10+
end

src/resources/application.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ struct ApplicationResources
2727
files ::Dict{String, NamespaceFiles}
2828
css ::Vector{AppResource}
2929
js ::Vector{AppResource}
30-
favicon ::Union{Nothing, String}
30+
favicon ::Union{Nothing, AppAssetResource}
3131
ApplicationResources(files, css, js, favicon) = new(files, css, js, favicon)
3232
end
3333

3434

3535
function ApplicationResources(app::DashApp, registry::ResourcesRegistry)
3636
css = AppResource[]
3737
js = AppResource[]
38-
favicon::Union{Nothing, String} = nothing
38+
favicon::Union{Nothing, AppResource} = nothing
3939
files = Dict{String, NamespaceFiles}()
40-
40+
4141
serve_locally = get_setting(app, :serve_locally)
4242
assets_external_path = get_setting(app, :assets_external_path)
4343
dev = get_devsetting(app, :serve_dev_bundles)
4444
eager_loading = get_setting(app, :eager_loading)
45-
45+
4646
append_pkg = function(pkg)
4747
append!(css,
4848
_convert_resource_pkg(pkg, :css, dev = dev, serve_locally = serve_locally, eager_loading = eager_loading)
@@ -58,10 +58,10 @@ function ApplicationResources(app::DashApp, registry::ResourcesRegistry)
5858

5959
append_pkg(get_dash_dependencies(registry, get_devsetting(app, :props_check)))
6060

61-
append!(css,
61+
append!(css,
6262
_convert_external.(get_setting(app, :external_stylesheets))
6363
)
64-
append!(js,
64+
append!(js,
6565
_convert_external.(get_setting(app, :external_scripts))
6666
)
6767

@@ -72,7 +72,7 @@ function ApplicationResources(app::DashApp, registry::ResourcesRegistry)
7272
elseif type == :css
7373
push!(css, asset_resource(url, modified))
7474
elseif type == :favicon
75-
favicon = url
75+
favicon = AppAssetResource(url, modified)
7676
end
7777
end
7878
end
@@ -113,7 +113,7 @@ function walk_assets(callback, app::DashApp)
113113
assets_filter = isempty(assets_ignore) ?
114114
(f) -> true :
115115
(f) -> !occursin(assets_regex, f)
116-
116+
117117
assets_path = get_assets_path(app)
118118
if get_setting(app, :include_assets_files) && isdir(assets_path)
119119
for (base, dirs, files) in walkdir(assets_path)
@@ -181,9 +181,9 @@ function _convert_resource_pkg(pkg::ResourcePkg, type::Symbol; dev, serve_locall
181181
ts = ispath(pkg.path) ? trunc(Int64, stat(pkg.path).mtime) : 0
182182
for resource in iterator
183183
append!(
184-
result,
184+
result,
185185
_convert_resource(
186-
resource,
186+
resource,
187187
namespace = pkg.namespace,
188188
version = pkg.version,
189189
ts = ts,

0 commit comments

Comments
 (0)