2121
2222DEFAULT_CDN = "https://cdn.jsdelivr.net/gh/wang0618/PyWebIO-assets@v{version}/"
2323
24- _global_config = {'title' : 'PyWebIO Application' }
24+ _global_config = {}
2525config_keys = ['title' , 'description' , 'js_file' , 'js_code' , 'css_style' , 'css_file' , 'theme' , 'manifest' ]
2626AppMeta = namedtuple ('App' , config_keys )
2727
@@ -51,8 +51,8 @@ def render_page(app, protocol, cdn):
5151 theme = environ .get ('PYWEBIO_THEME' , meta .theme ) or 'default'
5252 check_theme (theme )
5353
54- return _index_page_tpl .generate (title = meta .title , description = meta .description , protocol = protocol ,
55- script = True , content = '' , base_url = base_url , version = version ,
54+ return _index_page_tpl .generate (title = meta .title or 'PyWebIO Application' , description = meta .description ,
55+ protocol = protocol , script = True , content = '' , base_url = base_url , version = version ,
5656 js_file = meta .js_file or [], js_code = meta .js_code , css_style = meta .css_style ,
5757 css_file = meta .css_file or [], theme = theme , manifest = manifest )
5858
@@ -69,31 +69,26 @@ def check_theme(theme):
6969
7070
7171def parse_app_metadata (func ) -> AppMeta :
72- """Get metadata form pywebio task function, fallback to global config in empty meta field. """
72+ """Get metadata for pywebio task function"""
7373 prefix = '_pywebio_'
7474 attrs = get_function_attr (func , [prefix + k for k in config_keys ])
75- meta = AppMeta ( ** {k : attrs .get (prefix + k ) for k in config_keys })
75+ meta = {k : attrs .get (prefix + k ) for k in config_keys }
7676
77+ # fallback to title and description from docstring
7778 doc = get_function_doc (func )
7879 parts = doc .strip ().split ('\n \n ' , 1 )
7980 if len (parts ) == 2 :
8081 title , description = parts
8182 else :
8283 title , description = parts [0 ], ''
83-
84- if not title :
85- title = get_function_name (func )
86-
87- if not meta .title :
88- meta = meta ._replace (title = title , description = description )
84+ meta ['title' ] = meta .get ('title' ) or title
85+ meta ['description' ] = meta .get ('description' ) or description
8986
9087 # fallback to global config
9188 for key in config_keys :
92- if not getattr (meta , key , None ) and _global_config .get (key ):
93- kwarg = {key : _global_config .get (key )}
94- meta = meta ._replace (** kwarg )
89+ meta [key ] = meta [key ] or _global_config .get (key )
9590
96- return meta
91+ return AppMeta ( ** meta )
9792
9893
9994_app_list_tpl = template .Template ("""
0 commit comments