~fkfd/git.gmi

5d8be65e92141c86b960692bfb4a68610f6f1a59 — Frederick Yin 1 year, 2 months ago c6d8683
Show path in tree view
1 files changed, 10 insertions(+), 5 deletions(-)

M git-gmi/git.py
M git-gmi/git.py => git-gmi/git.py +10 -5
@@ 111,8 111,7 @@ class GitGmiRepo:
        refs = self.get_refs()
        for ref in refs:
            response += (
                f"## {ref['shorthand']}\n"
                f"=> tree/{ref['shorthand']}/ view tree\n\n"
                f"## {ref['shorthand']}\n=> tree/{ref['shorthand']}/ view tree\n\n"
            )
        return response



@@ 169,7 168,7 @@ class GitGmiRepo:
                    {
                        "type": "dir",
                        "name": item[0],
                        "size": len(item[1]),  # number of objects in dir
                        "items": len(item[1]),  # number of objects in dir
                    }
                )



@@ 188,13 187,19 @@ class GitGmiRepo:
    def view_tree(self, branch: str, location=[]) -> str:
        # actual Gemini response
        # consists of a header and a body
        response = f"{STATUS_SUCCESS} {META_GEMINI}\n" + self.generate_header()
        tree = self.get_tree(branch)
        contents = self.list_tree(tree, location)
        items = len(contents)
        response = (
            f"{STATUS_SUCCESS} {META_GEMINI}\n"
            + self.generate_header()
            + f"## {self.name}{'/' if location else ''}{'/'.join(location)}/"
            f" | {items} {'items' if items > 1 else 'item'}\n\n"
        )
        for item in contents:
            if item["type"] == "dir":
                response += (
                    f"=> {item['name']}/ {item['name']}/ | {item['size']} items\n"
                    f"=> {item['name']}/ {item['name']}/ | {item['items']} items\n"
                )
            elif item["type"] == "file":
                response += f"=> {item['name']} {item['name']} | {convert_filesize(item['size'])}\n"