mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-26 02:47:47 +02:00
handle folder that contains only one folder
This commit is contained in:
@@ -125,6 +125,7 @@ class Anonymous_Github:
|
|||||||
or ".lua" in file.name \
|
or ".lua" in file.name \
|
||||||
or ".py" in file.name \
|
or ".py" in file.name \
|
||||||
or ".sh" in file.name \
|
or ".sh" in file.name \
|
||||||
|
or ".gitignore" in file.name \
|
||||||
or ".travis.yml" in file.name:
|
or ".travis.yml" in file.name:
|
||||||
return Markup("<pre><code>{}</code></pre>")\
|
return Markup("<pre><code>{}</code></pre>")\
|
||||||
.format(Markup.escape(remove_terms(file.decoded_content.decode("utf-8"), repository_configuration)))
|
.format(Markup.escape(remove_terms(file.decoded_content.decode("utf-8"), repository_configuration)))
|
||||||
@@ -297,6 +298,18 @@ class Anonymous_Github:
|
|||||||
"""
|
"""
|
||||||
return path[:4] == "docs"
|
return path[:4] == "docs"
|
||||||
|
|
||||||
|
def is_default_file(f):
|
||||||
|
try:
|
||||||
|
f.name.lower().index("readme")
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
try:
|
||||||
|
f.name.lower().index("index")
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
def get_current_folder_files(path, current_file, repository_config, g_repo, g_commit):
|
def get_current_folder_files(path, current_file, repository_config, g_repo, g_commit):
|
||||||
"""
|
"""
|
||||||
get the list of files of the current repository
|
get the list of files of the current repository
|
||||||
@@ -312,7 +325,7 @@ class Anonymous_Github:
|
|||||||
if type(current_file) is not github.ContentFile.ContentFile:
|
if type(current_file) is not github.ContentFile.ContentFile:
|
||||||
files = g_repo.get_git_tree(g_commit.sha)
|
files = g_repo.get_git_tree(g_commit.sha)
|
||||||
for f in current_file:
|
for f in current_file:
|
||||||
if f.name.lower() == "readme" or f.name.lower() == "index.html":
|
if is_default_file(f):
|
||||||
current_file = f
|
current_file = f
|
||||||
break
|
break
|
||||||
if type(current_file) is not github.ContentFile.ContentFile:
|
if type(current_file) is not github.ContentFile.ContentFile:
|
||||||
@@ -325,10 +338,10 @@ class Anonymous_Github:
|
|||||||
else:
|
else:
|
||||||
files = g_repo.get_git_tree(current_file.sha)
|
files = g_repo.get_git_tree(current_file.sha)
|
||||||
for f in files.tree:
|
for f in files.tree:
|
||||||
if f.path.lower() == "readme.md" or f.path.lower() == "index.html":
|
if is_default_file(f):
|
||||||
current_file = get_element_from_path(g_repo, g_commit, os.path.join(path, f.path))
|
current_file = get_element_from_path(g_repo, g_commit, os.path.join(path, f.path))
|
||||||
break
|
break
|
||||||
if len(files.tree) == 1:
|
if len(files.tree) == 1 and type(files.tree[0]) is github.ContentFile.ContentFile:
|
||||||
current_file = get_element_from_path(g_repo, g_commit, os.path.join(path, files.tree[0].path))
|
current_file = get_element_from_path(g_repo, g_commit, os.path.join(path, files.tree[0].path))
|
||||||
return files, current_file
|
return files, current_file
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@
|
|||||||
<span class="path"><a href="{{ current_path|join("/") }}">Root</a></span>
|
<span class="path"><a href="{{ current_path|join("/") }}">Root</a></span>
|
||||||
{% for item in path %}
|
{% for item in path %}
|
||||||
{% do current_path.append(item) %}
|
{% do current_path.append(item) %}
|
||||||
<span class="path"><a href="{{ current_path|join("/") }}">{{ item }}</a></span>
|
<span class="path"><a href="{{ current_path|join("/") }}">{{ item|remove_terms(repository) }}</a></span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<div class="files">
|
<div class="files">
|
||||||
|
|||||||
Reference in New Issue
Block a user