~sircmpwn/sr.ht-dev

git.sr.ht: Render symlinks as hyperlinks v1 PROPOSED

наб: 2
 Render symlinks as hyperlinks
 Render symlinks as hyperlinks

 4 files changed, 13 insertions(+), 7 deletions(-)
#304947 alpine.yml failed
#304948 archlinux.yml success
#304949 debian.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/13944/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH git.sr.ht] Render symlinks as hyperlinks Export this patch

---
 gitsrht/blueprints/repo.py   | 9 +++++++--
 gitsrht/templates/blame.html | 2 +-
 gitsrht/templates/blob.html  | 2 +-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py
index b5afb7d..72edfd0 100644
--- a/gitsrht/blueprints/repo.py
+++ b/gitsrht/blueprints/repo.py
@@ -15,6 +15,7 @@ from gitsrht.rss import generate_feed
from gitsrht.types import Artifact
from io import BytesIO
from jinja2 import Markup
from jinja2.utils import url_quote, escape
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import guess_lexer, guess_lexer_for_filename, TextLexer
@@ -53,10 +54,14 @@ def get_readme(repo, git_repo, tip, link_prefix=None):
    return get_formatted_readme("git.sr.ht:git", file_finder, content_getter,
            link_prefix=link_prefix)

def _highlight_file(repo, ref, name, data, blob_id, commit_id):
def _highlight_file(repo, ref, entry, data, blob_id, commit_id):
    link_prefix = url_for('repo.tree', owner=repo.owner,
            repo=repo.name, ref=ref)
    return get_highlighted_file("git.sr.ht:git", name, blob_id, data)
    if entry.filemode == pygit2.GIT_FILEMODE_LINK:
        return Markup(f"<a href=\"{url_quote(data.encode('utf-8'))}\">" +
                f"{escape(data)}</a>")
    else:
        return get_highlighted_file("git.sr.ht:git", entry.name, blob_id, data)

def render_empty_repo(owner, repo):
    origin = cfg("git.sr.ht", "origin")
diff --git a/gitsrht/templates/blame.html b/gitsrht/templates/blame.html
index c091c22..295902e 100755
--- a/gitsrht/templates/blame.html
+++ b/gitsrht/templates/blame.html
@@ -82,7 +82,7 @@ pre, body {
        id="L{{loop.index}}"
        >{{loop.index}}</a>
{% endfor %}</pre>
      {{ highlight_file(repo, ref, entry.name,
      {{ highlight_file(repo, ref, entry,
        data, blob.id.hex, commit.id.hex) }}
    </div>
  </div>
diff --git a/gitsrht/templates/blob.html b/gitsrht/templates/blob.html
index 45e6821..60e6215 100644
--- a/gitsrht/templates/blob.html
+++ b/gitsrht/templates/blob.html
@@ -86,7 +86,7 @@ pre, body {
        id="L{{loop.index}}"
        >{{loop.index}}</a>{% if not loop.last %}
{% endif %}{% endfor %}</pre>
      {{ highlight_file(repo, ref, entry.name,
      {{ highlight_file(repo, ref, entry,
        data, blob.id.hex, commit.id.hex) }}
    </div>
    {% else %}
-- 
2.20.1
Thanks!

To git@git.sr.ht:~sircmpwn/git.sr.ht
   9b541f8..5dae4f3  master -> master
Hi наб,

it seems like the layout got somewhat messed up:
https://s2.imghost.eu/2020/09/17/Screenshot-at-2020-09-17-19-35-34.png

Testrepo shows the same behaviour:
https://git.sr.ht/~rwa/testrepo
https://git.sr.ht/~rwa/testrepo/tree/master/symlink.md?view-source



René
builds.sr.ht
git.sr.ht/patches: FAILED in 6m55s

[Render symlinks as hyperlinks][0] from [наб][1]

[0]: https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/13944
[1]: mailto:nabijaczleweli@nabijaczleweli.xyz

✓ #304949 SUCCESS git.sr.ht/patches/debian.yml    https://builds.sr.ht/~sircmpwn/job/304949
✗ #304947 FAILED  git.sr.ht/patches/alpine.yml    https://builds.sr.ht/~sircmpwn/job/304947
✓ #304948 SUCCESS git.sr.ht/patches/archlinux.yml https://builds.sr.ht/~sircmpwn/job/304948

Re: [PATCH git.sr.ht] Render symlinks as hyperlinks Export this patch

On Thu, Sep 17, 2020 at 08:15:09PM +0200, René Wagner wrote:
> it seems like the layout got somewhat messed up:
> https://s2.imghost.eu/2020/09/17/Screenshot-at-2020-09-17-19-35-34.png
Confirmed, thanks; it looked fine in Lynx, I hadn't tested with a normal
browser; see below for scissor-patch that wraps this in the right
elements to get it laid out properly.

-- >8 --
From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <nabijaczleweli@nabijaczleweli.xyz>
Subject: [PATCH git.sr.ht] Wrap symlink content properly for layout

---
 gitsrht/blueprints/repo.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py
index c1c5013..aa17ec1 100644
--- a/gitsrht/blueprints/repo.py
+++ b/gitsrht/blueprints/repo.py
@@ -57,9 +57,10 @@ def get_readme(repo, git_repo, tip, link_prefix=None):
def _highlight_file(repo, ref, entry, data, blob_id, commit_id):
    link_prefix = url_for('repo.tree', owner=repo.owner,
            repo=repo.name, ref=ref)
    if entry.filemode == pygit2.GIT_FILEMODE_LINK:
        return Markup(f"<a href=\"{url_quote(data.encode('utf-8'))}\">" +
                f"{escape(data)}</a>")
    if blob.filemode == pygit2.GIT_FILEMODE_LINK:
        return Markup("<div class=\"highlight\"><pre>" +
                f"<a href=\"{url_quote(data.encode('utf-8'))}\">" +
                f"{escape(data)}</a><pre></div>")
    else:
        return get_highlighted_file("git.sr.ht:git", entry.name, blob_id, data)

-- 
2.20.1