Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def build_nav(config):
# TODO: Allow more than two levels of nav.
ret = []
for path, title in config['index']:
url = path_to_url(path, config)
title, sep, child_title = title.partition('/')
title = title.strip()
child_title = child_title.strip()
if not child_title:
# New top level nav item
nav = NavItem(title=title, url=url, children=[])
ret.append(nav)
elif not ret or (ret[-1].title != title):
# New second level nav item
child = NavItem(title=child_title, url=url, children=[])
nav = NavItem(title=title, url=None, children=[child])
ret.append(nav)
else:
# Additional second level nav item
child = NavItem(title=child_title, url=url, children=[])
ret[-1].children.append(child)
return ret
def build_nav(config):
# TODO: Allow more than two levels of nav.
ret = []
for path, title in config['index']:
url = path_to_url(path, config)
title, sep, child_title = title.partition('/')
title = title.strip()
child_title = child_title.strip()
if not child_title:
# New top level nav item
nav = NavItem(title=title, url=url, children=[])
ret.append(nav)
elif not ret or (ret[-1].title != title):
# New second level nav item
child = NavItem(title=child_title, url=url, children=[])
nav = NavItem(title=title, url=None, children=[child])
ret.append(nav)
else:
# Additional second level nav item
child = NavItem(title=child_title, url=url, children=[])
ret[-1].children.append(child)
return ret
def build_nav(config):
# TODO: Allow more than two levels of nav.
ret = []
for path, title in config['index']:
url = path_to_url(path, config)
title, sep, child_title = title.partition('/')
title = title.strip()
child_title = child_title.strip()
if not child_title:
# New top level nav item
nav = NavItem(title=title, url=url, children=[])
ret.append(nav)
elif not ret or (ret[-1].title != title):
# New second level nav item
child = NavItem(title=child_title, url=url, children=[])
nav = NavItem(title=title, url=None, children=[child])
ret.append(nav)
else:
# Additional second level nav item
child = NavItem(title=child_title, url=url, children=[])
ret[-1].children.append(child)
return ret
url = path_to_url(path, config)
title, sep, child_title = title.partition('/')
title = title.strip()
child_title = child_title.strip()
if not child_title:
# New top level nav item
nav = NavItem(title=title, url=url, children=[])
ret.append(nav)
elif not ret or (ret[-1].title != title):
# New second level nav item
child = NavItem(title=child_title, url=url, children=[])
nav = NavItem(title=title, url=None, children=[child])
ret.append(nav)
else:
# Additional second level nav item
child = NavItem(title=child_title, url=url, children=[])
ret[-1].children.append(child)
return ret