Maverick
Maverick copied to clipboard
TypeError in Router.py during build process
Description
I encountered a TypeError
when attempting to build my site using Maverick. The error message indicates that a NoneType
object is being found where a str
instance is expected.
Error Log
Traceback (most recent call last):
File "./build.py", line 43, in <module>
main(sys.argv[1:])
File "./build.py", line 39, in main
builder.build_all()
File "/home/runner/work/Blog-With-GitHub-Boilerplate/Blog-With-GitHub-Boilerplate/Maverick/Maverick/Builder.py", line 173, in build_all
self._template.render(self._config, self._posts, self._pages)
File "/home/runner/work/Blog-With-GitHub-Boilerplate/Blog-With-GitHub-Boilerplate/Galileo/__init__.py", line 22, in render
Galileo(conf, posts, pages)()
File "/home/runner/work/Blog-With-GitHub-Boilerplate/Blog-With-GitHub-Boilerplate/Maverick/Maverick/Template.py", line 155, in __call__
self.render()
File "/home/runner/work/Blog-With-GitHub-Boilerplate/Blog-With-GitHub-Boilerplate/Galileo/__init__.py", line 39, in render
self.build_search_cache()
File "/home/runner/work/Blog-With-GitHub-Boilerplate/Blog-With-GitHub-Boilerplate/Maverick/Maverick/Utils.py", line 42, in wrapper
func(*args, **kwargs)
File "/home/runner/work/Blog-With-GitHub-Boilerplate/Blog-With-GitHub-Boilerplate/Galileo/__init__.py", line 266, in build_search_cache
cache_str = render_search_cache(self._posts, self._pages)
File "/home/runner/work/Blog-With-GitHub-Boilerplate/Blog-With-GitHub-Boilerplate/Galileo/__init__.py", line 256, in render_search_cache
posts = [gen_entry(post) for post in post_list if not post.skip]
File "/home/runner/work/Blog-With-GitHub-Boilerplate/Blog-With-GitHub-Boilerplate/Galileo/__init__.py", line 256, in <listcomp>
posts = [gen_entry(post) for post in post_list if not post.skip]
File "/home/runner/work/Blog-With-GitHub-Boilerplate/Blog-With-GitHub-Boilerplate/Galileo/__init__.py", line 252, in gen_entry
"permalink": router.gen_permalink('tag', tag, 1)
File "/home/runner/work/Blog-With-GitHub-Boilerplate/Blog-With-GitHub-Boilerplate/Maverick/Maverick/Router.py", line 35, in gen_permalink
link, _ = self.gen(type, slug, page)
File "/home/runner/work/Blog-With-GitHub-Boilerplate/Blog-With-GitHub-Boilerplate/Maverick/Maverick/Router.py", line 60, in gen
path = "/".join(routes)
TypeError: sequence item 1: expected str instance, NoneType found
Analysis
It appears that the error occurs in the gen()
method in Router.py
when the routes
list contains a None
value. This can happen if type
or slug
are not correctly defined.
Proposed Solution
I suggest adding a validation check in the gen()
method to ensure that no None
values are present in the routes
list before attempting to join them into a path.
Here is a potential fix for Router.py
:
# -*- coding: utf-8 -*-
class Router:
def __init__(self, conf):
self.config = conf
def gen_static_file_prefix(self):
if self.config.enable_jsdelivr['enabled']:
return "https://cdn.jsdelivr.net/gh/%s/" % \
self.config.enable_jsdelivr["repo"]
else:
return self.config.site_prefix
def gen_permalink_by_meta(self, meta):
link, _ = self.gen_by_meta(meta)
return link
def gen_permalink_by_content(self, content):
link, _ = self.gen_by_content(content)
return link
def gen_permalink(self, type, slug, page=0):
link, _ = self.gen(type, slug, page)
return link
def gen_by_meta(self, meta):
return self.gen(meta["layout"], meta["slug"])
def gen_by_content(self, content):
return self.gen(content.get_meta('layout'), content.get_meta('slug'))
def gen(self, type, slug, page=1):
routes = list()
if type == "post":
routes = ["archives", slug]
elif type == "page":
routes = [slug]
elif type == "tag" or type == "category":
routes = [type, slug]
elif type == "archives":
routes = ["archives"]
elif type == "index" and page > 1:
routes = ["page"]
if page > 1:
routes.append(str(page))
if any(r is None for r in routes):
raise ValueError(f"One of the routes is None: {routes}")
path = "/".join(routes)
if len(routes):
path += "/"
local_path = self.config.build_dir + path
permalink = self.config.site_prefix + path
return permalink, local_path
This code adds a check to raise a ValueError
if any None
values are found in the routes
list.
Steps to Reproduce
- Clone the repository.
- Set up the environment as described in the documentation.
- Attempt to build the site using the provided configuration and sample content.
Environment
- Operating System: [Your OS]
- Python Version: 3.7.17
- Maverick Version: [Commit Hash or Version Number]
Thank you for your assistance in resolving this issue.