]> git.ipfire.org Git - pbs.git/commitdiff
packages: Improve viewing files
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 27 Apr 2023 10:17:21 +0000 (10:17 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 27 Apr 2023 10:17:21 +0000 (10:17 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/packages.py
src/static/css/site.scss
src/templates/packages/view-file.html
src/web/ui_modules.py

index c244ece46a44403b98ca9f78a952b81a9d7b0eee..32f3acb9485c05e868e071d6fcfaffecfe8e3084 100644 (file)
@@ -310,7 +310,6 @@ dist_static_DATA = \
 staticdir = $(datadir)/static
 
 static_css_DATA = \
-       src/static/css/highlight.css \
        src/static/css/site.css
 
 static_cssdir = $(staticdir)/css
index ffbf873eb1d80f52447dfaafe6604ee345dc80bb..15529d2770a0955297161e5eb3a6ceb546cac00b 100644 (file)
@@ -557,6 +557,9 @@ class File(base.Object):
                self.package = package
                self.data = data
 
+       def __str__(self):
+               return self.path
+
        @property
        def path(self):
                return self.data.path
index a723168f12ae28df0b81c86d5d3f11d37fdb9952..268db64c9ffbce1182264dcc37c6de8ff7fc35fa 100644 (file)
@@ -60,3 +60,49 @@ $link:                                                       $primary;
                color: $danger-invert;
        }
 }
+
+/*
+       Code Highlighting
+*/
+.highlight {
+       .hll {
+               background-color: $grey;
+       }
+
+       // Keywords
+       .k, .kc, .kd, .kn, .kp, .kr, .kt {
+               color: $grey-dark;
+               font-weight: bold;
+       }
+
+       // Literals
+       .l, .ld {
+               color: $blue;
+       }
+
+       // Literal Number
+       .m, .mb, .mf, .mh, .mi, .mo, .il {
+               color: $red;
+       }
+
+       // Literal Strings
+       .s, .sa, .sb, .sc, .dl, .sd, .s2, .se, .sh, .si, .sx, .sr, .s1, .ss {
+               color: $blue;
+       }
+
+       // Names
+       .n, .na, .nb, .nc, .no, .nd, .ni, .ne, .nf, .nl, .nn, .nx, .py, .nt, .nv, .bp,
+                       .fm, .vc, .vg, .vi, .vm {
+               color: $text;
+       }
+
+       // Operators
+       .o, .ow {
+               color: $text;
+       }
+
+       // Comments
+       .c, .ch, .cm, .cp, .cpf, .c1, .cs {
+               color: $grey;
+       }
+}
index ff1077fd03f011ef7d1dcdfd3b925f0722d12001..5546d503b901b690f28862565262fc3a9ad69116 100644 (file)
@@ -1,28 +1,33 @@
 {% extends "../base.html" %}
 
-{% block title %}{{ _("Package") }} - {{ package }} - {{ file }}{% end block %}
+{% block title %}{{ package }} - {{ file }}{% end block %}
 
 {% block container %}
-       <nav aria-label="{{ _("You are here:") }}" role="navigation">
-               <ul class="breadcrumbs">
-                       <li>
-                               <a href="/">{{ _("Home") }}</a>
-                       </li>
+       <nav class="breadcrumb" aria-label="breadcrumbs">
+               <ul>
                        <li>
                                <a href="/packages">{{ _("Packages") }}</a>
                        </li>
                        <li>
                                <a href="/packages/{{ package.uuid }}">{{ package }}</a>
                        </li>
-                       <li>
-                               <span class="show-for-sr">{{ _("Current") }}: </span> {{ file.path }}
+                       <li class="is-active">
+                               <a href="#" aria-current="page">{{ _("File %s") % file }}</a>
                        </li>
                </ul>
        </nav>
 
-       {% module Highlight(payload) %}
+       <section class="section">
+               <h1 class="title">{{ file }}</h1>
+
+               <div class="block">
+                       {% module Highlight(payload, filename=file.path) %}
+               </div>
 
-       <a class="expanded primary button" href="/package/{{ package.uuid }}/download{{ file.path }}">
-               {{ _("Download (%s)") % format_size(file.size) }}
-       </a>
+               <div class="block">
+                       <a class="button" href="/package/{{ package.uuid }}/download{{ file.path }}">
+                               {{ _("Download (%s)") % format_size(file.size) }}
+                       </a>
+               </div>
+       </section>
 {% end block %}
index 8ef3ccee9e5bee25840f48a5b0f60685ea1625a8..28490da44cf05b57aedc7925749d42988c52e0c6 100644 (file)
@@ -59,23 +59,21 @@ class CVELinksPreprocessor(markdown.preprocessors.Preprocessor):
 
 
 class HighlightModule(UIModule):
-       def render(self, text):
+       def render(self, text, filename=None):
                # Find a lexer
                try:
-                       lexer = pygments.lexers.guess_lexer(text)
+                       if filename:
+                               lexer = pygments.lexers.guess_lexer_for_filename(filename, text)
+                       else:
+                               lexer = pygments.lexers.guess_lexer(text)
                except pygments.util.ClassNotFound as e:
                        lexer = pygments.lexers.special.TextLexer()
 
                # Find a formatter
-               formatter = pygments.formatters.HtmlFormatter(linenos="table")
+               formatter = pygments.formatters.HtmlFormatter()
 
                return pygments.highlight(text, lexer, formatter)
 
-       def css_files(self):
-               return (
-                       "css/highlight.css",
-               )
-
 
 class CommitMessageModule(UIModule):
        def render(self, commit):