From df66115b0cf46dabe9d7493193925fdf6549868a Mon Sep 17 00:00:00 2001 From: Julien Verneuil Date: Thu, 7 Apr 2016 16:58:13 +0200 Subject: [PATCH] remove duplicate js filenames when formating html head tags --- web/CXM_making_a_web_site.anubis | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis index 16db090..29e535f 100644 --- a/web/CXM_making_a_web_site.anubis +++ b/web/CXM_making_a_web_site.anubis @@ -50,7 +50,9 @@ read tools/basis.anubis read tools/printable_tree.anubis read tools/base64.anubis -read tools/random.anubis +read tools/random.anubis +read tools/dictionaries.anubis +read system/lists.anubis read system/string.anubis read system/logger.anubis read CXM_common.anubis @@ -4577,14 +4579,29 @@ define Printable_tree [h . t] then [format(cinfo,state_name,h,is_https) . format(cinfo,state_name,t,is_https,charset)] }. - + + define List(HTML_Head_Tag) + rebuild_html_head_tags + ( + List(HTML_Head_Tag) lwf, + List(HTML_Head_Tag) so_far + ) = + if lwf is + { + [] then so_far, + [h . t] then + rebuild_html_head_tags(t, append_once(so_far, h)) + }. + define Printable_tree _format_html_head ( List(HTML_Head_Tag) lwf, - Printable_tree so_far + Printable_tree so_far, + Dictionary(String, Word32) js_dict ) = + //with lwf_ = rebuild_html_head_tags(lwf, []), if lwf is { [] then reverse(so_far), @@ -4592,21 +4609,31 @@ define Printable_tree if h is { meta(meta) then - [format(meta) . _format_html_head(t, so_far)], + [format(meta) . _format_html_head(t, so_far, js_dict)], title(title) then - [""+title+"\n" . _format_html_head(t, so_far)], + [""+title+"\n" . _format_html_head(t, so_far, js_dict)], js(jsf) then - [add_js_files([jsf]) . _format_html_head(t, so_far)], + since jsf is js_file(filename, _), + if js_dict.get(filename) is + { + failure then + forget(js_dict.insert(filename, 0)); + [add_js_files([jsf]) . _format_html_head(t, so_far, js_dict)], + + success(_) then + _format_html_head(t, so_far, js_dict), + } js_inline(jsi) then if jsi is { - script(type, _) then ["\n" . _format_html_head(t, so_far)], + script(type, _) then + ["\n" . _format_html_head(t, so_far, js_dict)], } css(cssf) then since cssf is css_file(file_name, media), - ["\n" . _format_html_head(t, so_far)], + ["\n" . _format_html_head(t, so_far, js_dict)], css_inline(cssi) then - ["\n" . _format_html_head(t, so_far)] + ["\n" . _format_html_head(t, so_far, js_dict)] } } . @@ -4618,7 +4645,7 @@ public define Printable_tree String charset ) = - _format_html_head((List(HTML_Head_Tag))[ meta(http_equiv("content-type", "text/html; charset="+charset)) . lwf], []). + _format_html_head((List(HTML_Head_Tag))[ meta(http_equiv("content-type", "text/html; charset="+charset)) . lwf], [], make_dictionary((Word32)0, dictionaryComparerString)). public define Printable_tree format_html_head @@ -4626,7 +4653,7 @@ public define Printable_tree List(HTML_Head_Tag) lwf ) = - _format_html_head(lwf, []). + _format_html_head(lwf, [], make_dictionary((Word32)0, dictionaryComparerString)). public type HTML_ajax_content: -- libgit2 0.21.4