-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tree structure #34
Tree structure #34
Changes from 9 commits
feb22b6
2593e05
0324300
b791b94
93a2c7f
0cbb3ba
70c4bda
a1f47df
032166c
52888ae
8b99f0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,47 @@ | |
|
||
from jssg.templatetags.filter_opengraph_metadata import filter_opengraph_metadata | ||
|
||
from jssg.models import Document | ||
from django.conf import settings | ||
|
||
from jssg.models import Page | ||
|
||
def url_from_slug(slug) : | ||
url = "" | ||
pages_with_slug = "" | ||
|
||
for page in Page.load_glob(all=True) : | ||
if page.slug == slug : | ||
if pages_with_slug == "" : | ||
url = "/" + page.dir + "/" + page.slug + ".html" | ||
else : | ||
url = "" | ||
pages_with_slug += str(page.path.relative_to(page.page_dir.parent)) + ", " | ||
|
||
if url == "" and pages_with_slug != "" : | ||
raise Exception("url_slug() : slug '%s' is not unique, found in : [%s] ; use url_abs()" % (slug, pages_with_slug[:-2])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should return the list of paths where the slug is found. Eg: By the way, the coed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't directly return a list since it is the return value that is printed in the jinja2 template. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the |
||
elif url == "" : | ||
raise Exception("url_slug() : slug '%s' not found" % slug) | ||
return url | ||
|
||
def url_absolute(url_path) : | ||
dir = '/'.join(url_path.split('/')[:-1]) | ||
slug = ''.join((''.join(url_path.split('/')[-1])).split('.')[0]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code is quite complex. It looks like the This kind of code should at least come with an example. Something like Examples are extremly usefull in this context because there are always questions about "absolute or relative ?" "traling slash or no trailing slash?" etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have used re.findall() so we can check the format of the url given by user too |
||
|
||
for page in Page.get_pages() : | ||
if page["slug"] == slug and dir == "" : | ||
return "/" + slug + ".html" | ||
elif page["slug"] == slug and "dir" in page.keys() and page["dir"] == dir : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the condition about "dir" being in the keys? Is that a metadata? something else? Does this mean that a page (Document?) object as an attribute named dir? If so, I suggest to give a more explicity name. Is it a parent folder? a folder path? A parent folder path? The more explicit the name is, the more comprehensible it is for future maintainers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I renamed |
||
return "/" + dir + "/" + slug + ".html" | ||
|
||
raise Exception("url_abs() : page for %s url not found" % url_path) | ||
|
||
def environment(**options): | ||
env = Environment(**options) | ||
env.globals.update( | ||
{ | ||
"static": static, | ||
"url": reverse, | ||
"url_slug": url_from_slug, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think naming
|
||
"url_abs" : url_absolute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the same time, I suggest to rename |
||
} | ||
) | ||
env.filters.update( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add typing + some explanation: