diff options
| author | Elis Eriksson <spelis.tech@gmail.com> | 2026-03-26 19:08:03 +0100 |
|---|---|---|
| committer | Elis Eriksson <spelis.tech@gmail.com> | 2026-03-26 19:08:03 +0100 |
| commit | a2a39cb2287a29767fa3bc98d05f01430c668362 (patch) | |
| tree | 5428225706ae55714227f330e4f8503a96d9cee2 | |
| parent | 0d8e5fbc31e1082063bfb5155c35b7869721152b (diff) | |
| download | cgit-a2a39cb2287a29767fa3bc98d05f01430c668362.tar cgit-a2a39cb2287a29767fa3bc98d05f01430c668362.tar.gz cgit-a2a39cb2287a29767fa3bc98d05f01430c668362.tar.bz2 cgit-a2a39cb2287a29767fa3bc98d05f01430c668362.tar.lz cgit-a2a39cb2287a29767fa3bc98d05f01430c668362.tar.xz cgit-a2a39cb2287a29767fa3bc98d05f01430c668362.tar.zst cgit-a2a39cb2287a29767fa3bc98d05f01430c668362.zip | |
slight changes, idk how to write proper commit messages hehe
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | cgit.c | 10 | ||||
| -rw-r--r-- | cgit.css | 179 | ||||
| -rw-r--r-- | cgit.css.bak | 916 | ||||
| -rw-r--r-- | cgit.h | 2 | ||||
| -rw-r--r-- | cgit.mk | 1 | ||||
| -rw-r--r-- | cgit.png | bin | 1366 -> 1864 bytes | |||
| -rw-r--r-- | cmd.c | 3 | ||||
| -rw-r--r-- | favicon.ico | bin | 1078 -> 3383 bytes | |||
| -rwxr-xr-x | filters/html-converters/md2html | 282 | ||||
| -rwxr-xr-x | filters/syntax-highlighting.py | 2 | ||||
| -rw-r--r-- | font.ttf | bin | 0 -> 44884 bytes | |||
| -rw-r--r-- | lang.c | 169 | ||||
| -rw-r--r-- | lang.h | 6 | ||||
| -rw-r--r-- | shared.c | 4 | ||||
| -rw-r--r-- | ui-repolist.c | 603 | ||||
| -rw-r--r-- | ui-shared.c | 9 |
17 files changed, 1576 insertions, 611 deletions
@@ -87,6 +87,7 @@ install: all $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH) $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css + $(INSTALL) -m 0644 font.ttf $(DESTDIR)$(CGIT_DATA_PATH)/font.ttf $(INSTALL) -m 0644 cgit.js $(DESTDIR)$(CGIT_DATA_PATH)/cgit.js $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png $(INSTALL) -m 0644 favicon.ico $(DESTDIR)$(CGIT_DATA_PATH)/favicon.ico @@ -9,6 +9,7 @@ #define USE_THE_REPOSITORY_VARIABLE #include "cgit.h" +#include "lang.h" #include "cache.h" #include "cmd.h" #include "configfile.h" @@ -48,6 +49,10 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va if (!strcmp(name, "name")) repo->name = xstrdup(value); + else if (!strcmp(name, "primary_lang")) + repo->primary_lang = xstrdup(value); + else if (!strcmp(name, "lang_confidence")) + repo->lang_confidence = atoi(value); else if (!strcmp(name, "clone-url")) repo->clone_url = xstrdup(value); else if (!strcmp(name, "desc")) @@ -613,8 +618,9 @@ static int prepare_repo_cmd(int nongit) } ctx.page.title = fmtalloc("%s - %s", ctx.repo->name, ctx.repo->desc); - if (!ctx.repo->defbranch) + if (!ctx.repo->defbranch) { ctx.repo->defbranch = guess_defbranch(); + } if (!ctx.qry.head) { ctx.qry.nohead = 1; @@ -799,6 +805,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) { struct string_list_item *item; fprintf(f, "repo.url=%s\n", repo->url); + fprintf(f, "repo.primary_lang=%s\n", repo->primary_lang); + fprintf(f, "repo.lang_confidence=%d\n", repo->lang_confidence); fprintf(f, "repo.name=%s\n", repo->name); fprintf(f, "repo.path=%s\n", repo->path); if (repo->owner) @@ -1,3 +1,8 @@ +@font-face { + font-family: "CgitFont"; + src: url("./font.ttf") format("truetype"); +} + div#cgit { padding: 0em; margin: 0em; @@ -8,6 +13,10 @@ div#cgit { padding: 4px; } +div#cgit code { + font-family: "CgitFont"; +} + div#cgit a { color: blue; text-decoration: none; @@ -178,9 +187,12 @@ div#cgit table.list td { } div#cgit table.list td.commitgraph { - font-family: monospace; + font-family: "CgitFont", "Courier New", monospace; white-space: pre; } +div#cgit pre { + font-family: "CgitFont", "Courier New", monospace; +} div#cgit table.list td.commitgraph .column1 { color: #a00; @@ -207,12 +219,12 @@ div#cgit table.list td.commitgraph .column6 { } div#cgit table.list td.logsubject { - font-family: monospace; + font-family: "CgitFont", "Courier New", monospace; font-weight: bold; } div#cgit table.list td.logmsg { - font-family: monospace; + font-family: "CgitFont", "Courier New", monospace; white-space: pre; padding: 0 0.5em; } @@ -281,17 +293,17 @@ div#cgit div.error { } div#cgit a.ls-blob, div#cgit a.ls-dir, div#cgit .ls-mod { - font-family: monospace; + font-family: "CgitFont", "Courier New", monospace; } div#cgit td.ls-size { text-align: right; - font-family: monospace; + font-family: "CgitFont", "Courier New", monospace; width: 10em; } div#cgit td.ls-mode { - font-family: monospace; + font-family: "CgitFont", "Courier New", monospace; width: 10em; } @@ -378,14 +390,14 @@ div#cgit table.bin-blob { } div#cgit table.bin-blob th { - font-family: monospace; + font-family: "CgitFont", "Courier New", monospace; white-space: pre; border: solid 1px #777; padding: 0.5em 1em; } div#cgit table.bin-blob td { - font-family: monospace; + font-family: "CgitFont", "Courier New", monospace; white-space: pre; border-left: solid 1px #777; padding: 0em 1em; @@ -448,7 +460,7 @@ div#cgit div.commit-subject { div#cgit div.commit-msg { white-space: pre; - font-family: monospace; + font-family: "CgitFont", "Courier New", monospace; } div#cgit div.notes-header { @@ -458,7 +470,7 @@ div#cgit div.notes-header { div#cgit div.notes { white-space: pre; - font-family: monospace; + font-family: "CgitFont", "Courier New", monospace; border: solid 1px #ee9; background-color: #ffd; padding: 0.3em 2em 0.3em 1em; @@ -548,7 +560,7 @@ div#cgit table.diff { } div#cgit table.diff td { - font-family: monospace; + font-family: "CgitFont", "Courier New", monospace; white-space: pre; } @@ -571,7 +583,7 @@ div#cgit table.diff td div.del { } div#cgit .oid { - font-family: monospace; + font-family: "CgitFont", "Courier New", monospace; font-size: 90%; } @@ -815,7 +827,7 @@ div#cgit table.ssdiff { div#cgit table.ssdiff td { font-size: 75%; - font-family: monospace; + font-family: "CgitFont", "Courier New", monospace; white-space: pre; padding: 1px 4px 1px 4px; border-left: solid 1px #aaa; @@ -907,3 +919,144 @@ div#cgit table.ssdiff td.space { div#cgit table.ssdiff td.space div { min-height: 3em; } +div#cgit span.libravatar img.onhover { + display: none; + border: 1px solid gray; + padding: 0px; + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + border-radius: 4px; + width: 128px; + height: 128px; +} + +div#cgit span.libravatar img.inline { + -webkit-border-radius: 3px; + -moz-border-radius: 3px; + border-radius: 3px; + width: 13px; + height: 13px; + margin-right: 0.2em; + opacity: 0.6; +} + +div#cgit span.libravatar:hover > img.onhover { + display: block; + position: absolute; + margin-left: 1.5em; + background-color: #eeeeee; + box-shadow: 2px 2px 7px rgba(100,100,100,0.75); +} + +/* + Color overrides for browsers running in dark mode. + "only all and ..." forces very old browsers to ignore the media query: + https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries#improving_compatibility_with_older_browsers +*/ +:root { color-scheme: light dark; } +@media only all and (prefers-color-scheme: dark) { + html, div#cgit { color: #eee; background: #171717; } + div#cgit a { color: #3af; } + div#cgit .diffstat-header a { color: #28d; } + div#cgit table#header td.main a { color: #eee; } + div#cgit table#header td.sub { color: #999; } + div#cgit table.tabs { border-bottom-color: #444; } + div#cgit table.tabs td a { color: #888; } + div#cgit table.tabs td a.active { color: #fff; background-color: #444; } + div#cgit div.path { color: #eee; background-color: #333; } + div#cgit div.content { border-bottom-color: #bbb; } + div#cgit table.list tr { background: #171717; } + div#cgit table.list tr.logheader { background: #171717; } + div#cgit table.list tr:nth-child(even) { background: #171717; } + div#cgit table.list tr:nth-child(odd) { background: #1f1f1f; } + div#cgit table.list tr:hover { background: #333; } + div#cgit table.list tr.nohover { background: #171717; } + div#cgit table.list tr.nohover:hover { background: #171717; } + div#cgit table.list tr.nohover-highlight:hover:nth-child(even) { background: #171717; } + div#cgit table.list tr.nohover-highlight:hover:nth-child(odd) { background: #1f1f1f; } + div#cgit table.list td.commitgraph .column1 { color: #f55; } + div#cgit table.list td.commitgraph .column2 { color: #5f5; } + div#cgit table.list td.commitgraph .column3 { color: #ff5; } + div#cgit table.list td.commitgraph .column4 { color: #55f; } + div#cgit table.list td.commitgraph .column5 { color: #f5f; } + div#cgit table.list td.commitgraph .column6 { color: #5ff; } + div#cgit table.list td a { color: #eee; } + div#cgit table.list td a.ls-dir { color: #28d; } + div#cgit table.list td a:hover { color: #3af; } + div#cgit table#downloads { border-color: #888; } + div#cgit table#downloads th { background-color: #333; } + div#cgit div#blob { border-color: #eee; } + div#cgit table.blob { border-top-color: #eee; } + div#cgit table.blob td.hashes, + div#cgit table.blob td.lines { color: #eee; } + div#cgit table.blob td.linenumbers { border-right-color: gray; } + div#cgit table.blob td.linenumbers a, + div#cgit table.ssdiff td.lineno a { color: gray; } + div#cgit table.blob td.linenumbers a:hover, + div#cgit table.ssdiff td.lineno a:hover { color: #eee; } + div#cgit table.blame div.alt:nth-child(even) { background: #171717; } + div#cgit table.blame div.alt:nth-child(odd) { background: #1f1f1f; } + div#cgit table.bin-blob { border-color: #eee; } + div#cgit table.bin-blob th { border-color: #888; } + div#cgit table.bin-blob td { border-left-color: #888; } + div#cgit div.cgit-panel table { border-color: #555; background-color: #282828; } + div#cgit div.notes { border-color: #661; background-color: #220; } + div#cgit table.diffstat { border-color: #555; background-color: #282828; } + div#cgit table.diffstat td span.modechange { color: #c66; } + div#cgit table.diffstat td.add a { color: #6c6; } + div#cgit table.diffstat td.del a { color: #c66; } + div#cgit table.diffstat td.upd a { color: #3af; } + div#cgit table.diffstat td.graph td.add { background-color: #3a3; } + div#cgit table.diffstat td.graph td.rem { background-color: #a33; } + div#cgit div.diffstat-summary { color: #777; } + div#cgit table.diff td div.head { color: #eee; } + div#cgit table.diff td div.hunk { color: #28d; } + div#cgit table.diff td div.add { color: #6c6; } + div#cgit table.diff td div.del { color: #c66; } + div#cgit table.list td.reposection { color: #777; } + div#cgit ul.pager a { color: #888; } + div#cgit span.age-mins { color: #7f7; } + div#cgit span.age-hours { color: #7f7; } + div#cgit span.age-days { color: #9d9; } + div#cgit span.age-weeks { color: #bbb; } + div#cgit span.age-months { color: #888; } + div#cgit span.age-years { color: #666; } + div#cgit span.insertions { color: #7f7; } + div#cgit span.deletions { color: #e33; } + div#cgit div.footer { color: #555; } + div#cgit div.footer a { color: #555; } + div#cgit a.branch-deco { color: #fff; background-color: #361; border-color: #3b2; } + div#cgit a.tag-deco { color: #fff; background-color: #650; border-color: #ba3; } + div#cgit a.tag-annotated-deco { color: #fff; background-color: #840; border-color: #b96; } + div#cgit a.remote-deco { color: #fff; background-color: #348; border-color: #67c; } + div#cgit a.deco { color: #fff; background-color: #922; border-color: #d55; } + div#cgit a.branch-deco:hover, div#cgit table.list td a.branch-deco:hover, + div#cgit a.tag-deco:hover, div#cgit table.list td a.tag-deco:hover, + div#cgit a.tag-annotated-deco:hover, div#cgit table.list td a.tag-annotated-deco:hover, + div#cgit a.remote-deco:hover, div#cgit table.list td a.remote-deco:hover, + div#cgit a.deco:hover, div#cgit table.list td a.deco:hover { color: #fff; } + div#cgit table.stats { border-color: #555; } + div#cgit table.stats th { background-color: #333; border-color: #555; } + div#cgit table.stats td { border-color: #555; } + div#cgit table.stats td.sum { color: #5C7E9B; } + div#cgit table.vgraph { border-color: #eee; } + div#cgit table.vgraph th { background-color: #1f1f1f; border-color: black; } + div#cgit table.vgraph div.bar { background-color: #1f1f1f; } + div#cgit table.hgraph { border-color: #eee; } + div#cgit table.hgraph th { background-color: #1f1f1f; border-color: #eee; } + div#cgit table.hgraph div.bar { background-color: #1f1f1f; } + div#cgit table.ssdiff td { border-left-color: #555; border-right-color: #555; } + div#cgit table.ssdiff td.add { color: #eee; background: #353; } + div#cgit table.ssdiff td.add_dark { color: #eee; background: #030; } + div#cgit table.ssdiff span.add { background: #030; } + div#cgit table.ssdiff td.del { color: #eee; background: #533; } + div#cgit table.ssdiff td.del_dark { color: #eee; background: #411; } + div#cgit table.ssdiff span.del { background: #300; } + div#cgit table.ssdiff td.changed { color: #eee; background: #553; } + div#cgit table.ssdiff td.changed_dark { color: #eee; background: #330; } + div#cgit table.ssdiff td.lineno { color: #eee; background: #1f1f1f; } + div#cgit table.ssdiff td.hunk { color: #eee; background: #0D3D64; border-top-color: #555; border-bottom-color: #555; } + div#cgit table.ssdiff td.head { border-top-color: #555; border-bottom-color: #555; } + div#cgit table.ssdiff td.head div.head { color: #eee; } + div#cgit table.ssdiff td.foot { border-top-color: #555; } +} diff --git a/cgit.css.bak b/cgit.css.bak new file mode 100644 index 0000000..2bd4cab --- /dev/null +++ b/cgit.css.bak @@ -0,0 +1,916 @@ +div#cgit { + padding: 0em; + margin: 0em; + font-family: sans-serif; + font-size: 10pt; + color: #333; + background: white; + padding: 4px; +} + +div#cgit a { + color: blue; + text-decoration: none; +} + +div#cgit a:hover { + text-decoration: underline; +} + +div#cgit table { + border-collapse: collapse; +} + +div#cgit table#header { + width: 100%; + margin-bottom: 1em; +} + +div#cgit table#header td.logo { + width: 96px; + vertical-align: top; +} + +div#cgit table#header td.main { + font-size: 250%; + padding-left: 10px; + white-space: nowrap; +} + +div#cgit table#header td.main a { + color: #000; +} + +div#cgit table#header td.form { + text-align: right; + vertical-align: bottom; + padding-right: 1em; + padding-bottom: 2px; + white-space: nowrap; +} + +div#cgit table#header td.form form, +div#cgit table#header td.form input, +div#cgit table#header td.form select { + font-size: 90%; +} + +div#cgit table#header td.sub { + color: #777; + border-top: solid 1px #ccc; + padding-left: 10px; +} + +div#cgit table.tabs { + border-bottom: solid 3px #ccc; + border-collapse: collapse; + margin-top: 2em; + margin-bottom: 0px; + width: 100%; +} + +div#cgit table.tabs td { + padding: 0px 1em; + vertical-align: bottom; +} + +div#cgit table.tabs td a { + padding: 2px 0.75em; + color: #777; + font-size: 110%; +} + +div#cgit table.tabs td a.active { + color: #000; + background-color: #ccc; +} + +div#cgit table.tabs a[href^="http://"]:after, div#cgit table.tabs a[href^="https://"]:after { + content: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfgAhcJDQY+gm2TAAAAHWlUWHRDb21tZW50AAAAAABDcmVhdGVkIHdpdGggR0lNUGQuZQcAAABbSURBVAhbY2BABs4MU4CwhYHBh2Erww4wrGFQZHjI8B8IgUIscJWyDHcggltQhI4zGDCcRwhChPggHIggP1QoAVmQkSETrGoHsiAEsACtBYN0oDAMbgU6EBcAAL2eHUt4XUU4AAAAAElFTkSuQmCC); + opacity: 0.5; + margin: 0 0 0 5px; +} + +div#cgit table.tabs td.form { + text-align: right; +} + +div#cgit table.tabs td.form form { + padding-bottom: 2px; + font-size: 90%; + white-space: nowrap; +} + +div#cgit table.tabs td.form input, +div#cgit table.tabs td.form select { + font-size: 90%; +} + +div#cgit div.path { + margin: 0px; + padding: 5px 2em 2px 2em; + color: #000; + background-color: #eee; +} + +div#cgit div.content { + margin: 0px; + padding: 2em; + border-bottom: solid 3px #ccc; +} + + +div#cgit table.list { + width: 100%; + border: none; + border-collapse: collapse; +} + +div#cgit table.list tr { + background: white; +} + +div#cgit table.list tr.logheader { + background: #eee; +} + +div#cgit table.list tr:nth-child(even) { + background: #f7f7f7; +} + +div#cgit table.list tr:nth-child(odd) { + background: white; +} + +div#cgit table.list tr:hover { + background: #eee; +} + +div#cgit table.list tr.nohover { + background: white; +} + +div#cgit table.list tr.nohover:hover { + background: white; +} + +div#cgit table.list tr.nohover-highlight:hover:nth-child(even) { + background: #f7f7f7; +} + +div#cgit table.list tr.nohover-highlight:hover:nth-child(odd) { + background: white; +} + +div#cgit table.list th { + font-weight: bold; + /* color: #888; + border-top: dashed 1px #888; + border-bottom: dashed 1px #888; + */ + padding: 0.1em 0.5em 0.05em 0.5em; + vertical-align: baseline; +} + +div#cgit table.list td { + border: none; + padding: 0.1em 0.5em 0.1em 0.5em; +} + +div#cgit table.list td.commitgraph { + font-family: monospace; + white-space: pre; +} + +div#cgit table.list td.commitgraph .column1 { + color: #a00; +} + +div#cgit table.list td.commitgraph .column2 { + color: #0a0; +} + +div#cgit table.list td.commitgraph .column3 { + color: #aa0; +} + +div#cgit table.list td.commitgraph .column4 { + color: #00a; +} + +div#cgit table.list td.commitgraph .column5 { + color: #a0a; +} + +div#cgit table.list td.commitgraph .column6 { + color: #0aa; +} + +div#cgit table.list td.logsubject { + font-family: monospace; + font-weight: bold; +} + +div#cgit table.list td.logmsg { + font-family: monospace; + white-space: pre; + padding: 0 0.5em; +} + +div#cgit table.list td a { + color: black; +} + +div#cgit table.list td a.ls-dir { + font-weight: bold; + color: #00f; +} + +div#cgit table.list td a:hover { + color: #00f; +} + +div#cgit img { + border: none; +} + +div#cgit input#switch-btn { + margin: 2px 0px 0px 0px; +} + +div#cgit td#sidebar input.txt { + width: 100%; + margin: 2px 0px 0px 0px; +} + +div#cgit table#grid { + margin: 0px; +} + +div#cgit td#content { + vertical-align: top; + padding: 1em 2em 1em 1em; + border: none; +} + +div#cgit div#summary { + vertical-align: top; + margin-bottom: 1em; +} + +div#cgit table#downloads { + float: right; + border-collapse: collapse; + border: solid 1px #777; + margin-left: 0.5em; + margin-bottom: 0.5em; +} + +div#cgit table#downloads th { + background-color: #ccc; +} + +div#cgit div#blob { + border: solid 1px black; +} + +div#cgit div.error { + color: red; + font-weight: bold; + margin: 1em 2em; +} + +div#cgit a.ls-blob, div#cgit a.ls-dir, div#cgit .ls-mod { + font-family: monospace; +} + +div#cgit td.ls-size { + text-align: right; + font-family: monospace; + width: 10em; +} + +div#cgit td.ls-mode { + font-family: monospace; + width: 10em; +} + +div#cgit table.blob { + margin-top: 0.5em; + border-top: solid 1px black; +} + +div#cgit table.blob td.hashes, +div#cgit table.blob td.lines { + margin: 0; padding: 0 0 0 0.5em; + vertical-align: top; + color: black; +} + +div#cgit table.blob td.linenumbers { + margin: 0; padding: 0 0.5em 0 0.5em; + vertical-align: top; + text-align: right; + border-right: 1px solid gray; +} + +div#cgit table.blob pre { + padding: 0; margin: 0; +} + +div#cgit table.blob td.linenumbers a, +div#cgit table.ssdiff td.lineno a { + color: gray; + text-align: right; + text-decoration: none; +} + +div#cgit table.blob td.linenumbers a:hover, +div#cgit table.ssdiff td.lineno a:hover { + color: black; +} + +div#cgit table.blame td.hashes, +div#cgit table.blame td.lines, +div#cgit table.blame td.linenumbers { + padding: 0; +} + +div#cgit table.blame td.hashes div.alt, +div#cgit table.blame td.lines div.alt { + padding: 0 0.5em 0 0.5em; +} + +div#cgit table.blame td.linenumbers div.alt { + padding: 0 0.5em 0 0; +} + +div#cgit table.blame div.alt:nth-child(even) { + background: #eee; +} + +div#cgit table.blame div.alt:nth-child(odd) { + background: white; +} + +div#cgit table.blame td.lines > div { + position: relative; +} + +div#cgit table.blame td.lines > div > pre { + padding: 0 0 0 0.5em; + position: absolute; + top: 0; +} + +div#cgit table.blame .oid { + font-size: 100%; +} + +div#cgit table.bin-blob { + margin-top: 0.5em; + border: solid 1px black; +} + +div#cgit table.bin-blob th { + font-family: monospace; + white-space: pre; + border: solid 1px #777; + padding: 0.5em 1em; +} + +div#cgit table.bin-blob td { + font-family: monospace; + white-space: pre; + border-left: solid 1px #777; + padding: 0em 1em; +} + +div#cgit table.nowrap td { + white-space: nowrap; +} + +div#cgit table.commit-info { + border-collapse: collapse; + margin-top: 1.5em; +} + +div#cgit div.cgit-panel { + float: right; + margin-top: 1.5em; +} + +div#cgit div.cgit-panel table { + border-collapse: collapse; + border: solid 1px #aaa; + background-color: #eee; +} + +div#cgit div.cgit-panel th { + text-align: center; +} + +div#cgit div.cgit-panel td { + padding: 0.25em 0.5em; +} + +div#cgit div.cgit-panel td.label { + padding-right: 0.5em; +} + +div#cgit div.cgit-panel td.ctrl { + padding-left: 0.5em; +} + +div#cgit table.commit-info th { + text-align: left; + font-weight: normal; + padding: 0.1em 1em 0.1em 0.1em; + vertical-align: top; +} + +div#cgit table.commit-info td { + font-weight: normal; + padding: 0.1em 1em 0.1em 0.1em; +} + +div#cgit div.commit-subject { + font-weight: bold; + font-size: 125%; + margin: 1.5em 0em 0.5em 0em; + padding: 0em; +} + +div#cgit div.commit-msg { + white-space: pre; + font-family: monospace; +} + +div#cgit div.notes-header { + font-weight: bold; + padding-top: 1.5em; +} + +div#cgit div.notes { + white-space: pre; + font-family: monospace; + border: solid 1px #ee9; + background-color: #ffd; + padding: 0.3em 2em 0.3em 1em; + float: left; +} + +div#cgit div.notes-footer { + clear: left; +} + +div#cgit div.diffstat-header { + font-weight: bold; + padding-top: 1.5em; +} + +div#cgit table.diffstat { + border-collapse: collapse; + border: solid 1px #aaa; + background-color: #eee; +} + +div#cgit table.diffstat th { + font-weight: normal; + text-align: left; + text-decoration: underline; + padding: 0.1em 1em 0.1em 0.1em; + font-size: 100%; +} + +div#cgit table.diffstat td { + padding: 0.2em 0.2em 0.1em 0.1em; + font-size: 100%; + border: none; +} + +div#cgit table.diffstat td.mode { + white-space: nowrap; +} + +div#cgit table.diffstat td span.modechange { + padding-left: 1em; + color: red; +} + +div#cgit table.diffstat td.add a { + color: green; +} + +div#cgit table.diffstat td.del a { + color: red; +} + +div#cgit table.diffstat td.upd a { + color: blue; +} + +div#cgit table.diffstat td.graph { + width: 500px; + vertical-align: middle; +} + +div#cgit table.diffstat td.graph table { + border: none; +} + +div#cgit table.diffstat td.graph td { + padding: 0px; + border: 0px; + height: 7pt; +} + +div#cgit table.diffstat td.graph td.add { + background-color: #5c5; +} + +div#cgit table.diffstat td.graph td.rem { + background-color: #c55; +} + +div#cgit div.diffstat-summary { + color: #888; + padding-top: 0.5em; +} + +div#cgit table.diff { + width: 100%; +} + +div#cgit table.diff td { + font-family: monospace; + white-space: pre; +} + +div#cgit table.diff td div.head { + font-weight: bold; + margin-top: 1em; + color: black; +} + +div#cgit table.diff td div.hunk { + color: #009; +} + +div#cgit table.diff td div.add { + color: green; +} + +div#cgit table.diff td div.del { + color: red; +} + +div#cgit .oid { + font-family: monospace; + font-size: 90%; +} + +div#cgit .left { + text-align: left; +} + +div#cgit .right { + text-align: right; +} + +div#cgit table.list td.reposection { + font-style: italic; + color: #888; +} + +div#cgit a.button { + font-size: 80%; + padding: 0em 0.5em; +} + +div#cgit a.primary { + font-size: 100%; +} + +div#cgit a.secondary { + font-size: 90%; +} + +div#cgit td.toplevel-repo { + +} + +div#cgit table.list td.sublevel-repo { + padding-left: 1.5em; +} + +div#cgit ul.pager { + list-style-type: none; + text-align: center; + margin: 1em 0em 0em 0em; + padding: 0; +} + +div#cgit ul.pager li { + display: inline-block; + margin: 0.25em 0.5em; +} + +div#cgit ul.pager a { + color: #777; +} + +div#cgit ul.pager .current { + font-weight: bold; +} + +div#cgit span.age-mins { + font-weight: bold; + color: #080; +} + +div#cgit span.age-hours { + color: #080; +} + +div#cgit span.age-days { + color: #040; +} + +div#cgit span.age-weeks { + color: #444; +} + +div#cgit span.age-months { + color: #888; +} + +div#cgit span.age-years { + color: #bbb; +} + +div#cgit span.insertions { + color: #080; +} + +div#cgit span.deletions { + color: #800; +} + +div#cgit div.footer { + margin-top: 0.5em; + text-align: center; + font-size: 80%; + color: #ccc; +} + +div#cgit div.footer a { + color: #ccc; + text-decoration: none; +} + +div#cgit div.footer a:hover { + text-decoration: underline; +} + +div#cgit a.branch-deco { + color: #000; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: #88ff88; + border: solid 1px #007700; +} + +div#cgit a.tag-deco { + color: #000; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: #ffff88; + border: solid 1px #777700; +} + +div#cgit a.tag-annotated-deco { + color: #000; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: #ffcc88; + border: solid 1px #777700; +} + +div#cgit a.remote-deco { + color: #000; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: #ccccff; + border: solid 1px #000077; +} + +div#cgit a.deco { + color: #000; + margin: 0px 0.5em; + padding: 0px 0.25em; + background-color: #ff8888; + border: solid 1px #770000; +} + +div#cgit div.commit-subject a.branch-deco, +div#cgit div.commit-subject a.tag-deco, +div#cgit div.commit-subject a.tag-annotated-deco, +div#cgit div.commit-subject a.remote-deco, +div#cgit div.commit-subject a.deco { + margin-left: 1em; + font-size: 75%; +} + +div#cgit table.stats { + border: solid 1px black; + border-collapse: collapse; +} + +div#cgit table.stats th { + text-align: left; + padding: 1px 0.5em; + background-color: #eee; + border: solid 1px black; +} + +div#cgit table.stats td { + text-align: right; + padding: 1px 0.5em; + border: solid 1px black; +} + +div#cgit table.stats td.total { + font-weight: bold; + text-align: left; +} + +div#cgit table.stats td.sum { + color: #c00; + font-weight: bold; +/* background-color: #eee; */ +} + +div#cgit table.stats td.left { + text-align: left; +} + +div#cgit table.vgraph { + border-collapse: separate; + border: solid 1px black; + height: 200px; +} + +div#cgit table.vgraph th { + background-color: #eee; + font-weight: bold; + border: solid 1px white; + padding: 1px 0.5em; +} + +div#cgit table.vgraph td { + vertical-align: bottom; + padding: 0px 10px; +} + +div#cgit table.vgraph div.bar { + background-color: #eee; +} + +div#cgit table.hgraph { + border: solid 1px black; + width: 800px; +} + +div#cgit table.hgraph th { + background-color: #eee; + font-weight: bold; + border: solid 1px black; + padding: 1px 0.5em; +} + +div#cgit table.hgraph td { + vertical-align: middle; + padding: 2px 2px; +} + +div#cgit table.hgraph div.bar { + background-color: #eee; + height: 1em; +} + +div#cgit table.ssdiff { + width: 100%; +} + +div#cgit table.ssdiff td { + font-size: 75%; + font-family: monospace; + white-space: pre; + padding: 1px 4px 1px 4px; + border-left: solid 1px #aaa; + border-right: solid 1px #aaa; +} + +div#cgit table.ssdiff td.add { + color: black; + background: #cfc; + min-width: 50%; +} + +div#cgit table.ssdiff td.add_dark { + color: black; + background: #aca; + min-width: 50%; +} + +div#cgit table.ssdiff span.add { + background: #cfc; + font-weight: bold; +} + +div#cgit table.ssdiff td.del { + color: black; + background: #fcc; + min-width: 50%; +} + +div#cgit table.ssdiff td.del_dark { + color: black; + background: #caa; + min-width: 50%; +} + +div#cgit table.ssdiff span.del { + background: #fcc; + font-weight: bold; +} + +div#cgit table.ssdiff td.changed { + color: black; + background: #ffc; + min-width: 50%; +} + +div#cgit table.ssdiff td.changed_dark { + color: black; + background: #cca; + min-width: 50%; +} + +div#cgit table.ssdiff td.lineno { + color: black; + background: #eee; + text-align: right; + width: 3em; + min-width: 3em; +} + +div#cgit table.ssdiff td.hunk { + color: black; + background: #ccf; + border-top: solid 1px #aaa; + border-bottom: solid 1px #aaa; +} + +div#cgit table.ssdiff td.head { + border-top: solid 1px #aaa; + border-bottom: solid 1px #aaa; +} + +div#cgit table.ssdiff td.head div.head { + font-weight: bold; + color: black; +} + +div#cgit table.ssdiff td.foot { + border-top: solid 1px #aaa; + border-left: none; + border-right: none; + border-bottom: none; +} + +div#cgit table.ssdiff td.space { + border: none; +} + +div#cgit table.ssdiff td.space div { + min-height: 3em; +} + +/* Style definition file generated by highlight 3.9, http://www.andre-simon.de/ */ +/* Highlighting theme: Kwrite Editor */ +/* adapted for cgit */ +div#cgit table.blob .num { color:#b07e00; } +div#cgit table.blob .esc { color:#ff00ff; } +div#cgit table.blob .str { color:#bf0303; } +div#cgit table.blob .pps { color:#818100; } +div#cgit table.blob .slc { color:#838183; font-style:italic; } +div#cgit table.blob .com { color:#838183; font-style:italic; } +div#cgit table.blob .ppc { color:#008200; } +div#cgit table.blob .opt { color:#000000; } +div#cgit table.blob .lin { color:#555555; } +div#cgit table.blob .kwa { color:#000000; font-weight:bold; } +div#cgit table.blob .kwb { color:#0057ae; } +div#cgit table.blob .kwc { color:#000000; font-weight:bold; } +div#cgit table.blob .kwd { color:#010181; } @@ -119,6 +119,8 @@ struct cgit_repo { struct string_list submodules; int hide; int ignore; + char *primary_lang; + int lang_confidence; }; typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name, @@ -94,6 +94,7 @@ CGIT_OBJ_NAMES += ui-stats.o CGIT_OBJ_NAMES += ui-summary.o CGIT_OBJ_NAMES += ui-tag.o CGIT_OBJ_NAMES += ui-tree.o +CGIT_OBJ_NAMES += lang.o CGIT_OBJS := $(addprefix $(CGIT_PREFIX),$(CGIT_OBJ_NAMES)) @@ -60,8 +60,7 @@ static void about_fn(void) free(currenturl); free(redirect); } - } else - cgit_print_site_readme(); + } } static void blame_fn(void) diff --git a/favicon.ico b/favicon.ico Binary files differindex 56ff593..9ca618d 100644 --- a/favicon.ico +++ b/favicon.ico diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html index 59f43a8..cbf8902 100755 --- a/filters/html-converters/md2html +++ b/filters/html-converters/md2html @@ -6,288 +6,6 @@ from pygments.formatters import HtmlFormatter from markdown.extensions.toc import TocExtension sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') -sys.stdout.write(''' -<style> -.markdown-body { - font-size: 14px; - line-height: 1.6; - overflow: hidden; -} -.markdown-body>*:first-child { - margin-top: 0 !important; -} -.markdown-body>*:last-child { - margin-bottom: 0 !important; -} -.markdown-body a.absent { - color: #c00; -} -.markdown-body a.anchor { - display: block; - padding-left: 30px; - margin-left: -30px; - cursor: pointer; - position: absolute; - top: 0; - left: 0; - bottom: 0; -} -.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 { - margin: 20px 0 10px; - padding: 0; - font-weight: bold; - -webkit-font-smoothing: antialiased; - cursor: text; - position: relative; -} -.markdown-body h1 .mini-icon-link, .markdown-body h2 .mini-icon-link, .markdown-body h3 .mini-icon-link, .markdown-body h4 .mini-icon-link, .markdown-body h5 .mini-icon-link, .markdown-body h6 .mini-icon-link { - display: none; - color: #000; -} -.markdown-body h1:hover a.anchor, .markdown-body h2:hover a.anchor, .markdown-body h3:hover a.anchor, .markdown-body h4:hover a.anchor, .markdown-body h5:hover a.anchor, .markdown-body h6:hover a.anchor { - text-decoration: none; - line-height: 1; - padding-left: 0; - margin-left: -22px; - top: 15%; -} -.markdown-body h1:hover a.anchor .mini-icon-link, .markdown-body h2:hover a.anchor .mini-icon-link, .markdown-body h3:hover a.anchor .mini-icon-link, .markdown-body h4:hover a.anchor .mini-icon-link, .markdown-body h5:hover a.anchor .mini-icon-link, .markdown-body h6:hover a.anchor .mini-icon-link { - display: inline-block; -} -div#cgit .markdown-body h1 a.toclink, div#cgit .markdown-body h2 a.toclink, div#cgit .markdown-body h3 a.toclink, div#cgit .markdown-body h4 a.toclink, div#cgit .markdown-body h5 a.toclink, div#cgit .markdown-body h6 a.toclink { - color: black; -} -.markdown-body h1 tt, .markdown-body h1 code, .markdown-body h2 tt, .markdown-body h2 code, .markdown-body h3 tt, .markdown-body h3 code, .markdown-body h4 tt, .markdown-body h4 code, .markdown-body h5 tt, .markdown-body h5 code, .markdown-body h6 tt, .markdown-body h6 code { - font-size: inherit; -} -.markdown-body h1 { - font-size: 28px; - color: #000; -} -.markdown-body h2 { - font-size: 24px; - border-bottom: 1px solid #ccc; - color: #000; -} -.markdown-body h3 { - font-size: 18px; -} -.markdown-body h4 { - font-size: 16px; -} -.markdown-body h5 { - font-size: 14px; -} -.markdown-body h6 { - color: #777; - font-size: 14px; -} -.markdown-body p, .markdown-body blockquote, .markdown-body ul, .markdown-body ol, .markdown-body dl, .markdown-body table, .markdown-body pre { - margin: 15px 0; -} -.markdown-body hr { - border: 2px solid #ccc; -} -.markdown-body>h2:first-child, .markdown-body>h1:first-child, .markdown-body>h1:first-child+h2, .markdown-body>h3:first-child, .markdown-body>h4:first-child, .markdown-body>h5:first-child, .markdown-body>h6:first-child { - margin-top: 0; - padding-top: 0; -} -.markdown-body a:first-child h1, .markdown-body a:first-child h2, .markdown-body a:first-child h3, .markdown-body a:first-child h4, .markdown-body a:first-child h5, .markdown-body a:first-child h6 { - margin-top: 0; - padding-top: 0; -} -.markdown-body h1+p, .markdown-body h2+p, .markdown-body h3+p, .markdown-body h4+p, .markdown-body h5+p, .markdown-body h6+p { - margin-top: 0; -} -.markdown-body li p.first { - display: inline-block; -} -.markdown-body ul, .markdown-body ol { - padding-left: 30px; -} -.markdown-body ul.no-list, .markdown-body ol.no-list { - list-style-type: none; - padding: 0; -} -.markdown-body ul li>:first-child, .markdown-body ul li ul:first-of-type, .markdown-body ul li ol:first-of-type, .markdown-body ol li>:first-child, .markdown-body ol li ul:first-of-type, .markdown-body ol li ol:first-of-type { - margin-top: 0px; -} -.markdown-body ul li p:last-of-type, .markdown-body ol li p:last-of-type { - margin-bottom: 0; -} -.markdown-body ul ul, .markdown-body ul ol, .markdown-body ol ol, .markdown-body ol ul { - margin-bottom: 0; -} -.markdown-body dl { - padding: 0; -} -.markdown-body dl dt { - font-size: 14px; - font-weight: bold; - font-style: italic; - padding: 0; - margin: 15px 0 5px; -} -.markdown-body dl dt:first-child { - padding: 0; -} -.markdown-body dl dt>:first-child { - margin-top: 0px; -} -.markdown-body dl dt>:last-child { - margin-bottom: 0px; -} -.markdown-body dl dd { - margin: 0 0 15px; - padding: 0 15px; -} -.markdown-body dl dd>:first-child { - margin-top: 0px; -} -.markdown-body dl dd>:last-child { - margin-bottom: 0px; -} -.markdown-body blockquote { - border-left: 4px solid #DDD; - padding: 0 15px; - color: #777; -} -.markdown-body blockquote>:first-child { - margin-top: 0px; -} -.markdown-body blockquote>:last-child { - margin-bottom: 0px; -} -.markdown-body table th { - font-weight: bold; -} -.markdown-body table th, .markdown-body table td { - border: 1px solid #ccc; - padding: 6px 13px; -} -.markdown-body table tr { - border-top: 1px solid #ccc; - background-color: #fff; -} -.markdown-body table tr:nth-child(2n) { - background-color: #f8f8f8; -} -.markdown-body img { - max-width: 100%; - -moz-box-sizing: border-box; - box-sizing: border-box; -} -.markdown-body span.frame { - display: block; - overflow: hidden; -} -.markdown-body span.frame>span { - border: 1px solid #ddd; - display: block; - float: left; - overflow: hidden; - margin: 13px 0 0; - padding: 7px; - width: auto; -} -.markdown-body span.frame span img { - display: block; - float: left; -} -.markdown-body span.frame span span { - clear: both; - color: #333; - display: block; - padding: 5px 0 0; -} -.markdown-body span.align-center { - display: block; - overflow: hidden; - clear: both; -} -.markdown-body span.align-center>span { - display: block; - overflow: hidden; - margin: 13px auto 0; - text-align: center; -} -.markdown-body span.align-center span img { - margin: 0 auto; - text-align: center; -} -.markdown-body span.align-right { - display: block; - overflow: hidden; - clear: both; -} -.markdown-body span.align-right>span { - display: block; - overflow: hidden; - margin: 13px 0 0; - text-align: right; -} -.markdown-body span.align-right span img { - margin: 0; - text-align: right; -} -.markdown-body span.float-left { - display: block; - margin-right: 13px; - overflow: hidden; - float: left; -} -.markdown-body span.float-left span { - margin: 13px 0 0; -} -.markdown-body span.float-right { - display: block; - margin-left: 13px; - overflow: hidden; - float: right; -} -.markdown-body span.float-right>span { - display: block; - overflow: hidden; - margin: 13px auto 0; - text-align: right; -} -.markdown-body code, .markdown-body tt { - margin: 0 2px; - padding: 0px 5px; - border: 1px solid #eaeaea; - background-color: #f8f8f8; - border-radius: 3px; -} -.markdown-body code { - white-space: nowrap; -} -.markdown-body pre>code { - margin: 0; - padding: 0; - white-space: pre; - border: none; - background: transparent; -} -.markdown-body .highlight pre, .markdown-body pre { - background-color: #f8f8f8; - border: 1px solid #ccc; - font-size: 13px; - line-height: 19px; - overflow: auto; - padding: 6px 10px; - border-radius: 3px; -} -.markdown-body pre code, .markdown-body pre tt { - margin: 0; - padding: 0; - background-color: transparent; - border: none; -} -''') -sys.stdout.write(HtmlFormatter(style='pastie').get_style_defs('.highlight')) -sys.stdout.write(''' -</style> -''') sys.stdout.write("<div class='markdown-body'>") sys.stdout.flush() # Note: you may want to run this through bleach for sanitization diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py index e912594..3f608ad 100755 --- a/filters/syntax-highlighting.py +++ b/filters/syntax-highlighting.py @@ -34,7 +34,7 @@ sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace') data = sys.stdin.read() filename = sys.argv[1] -formatter = HtmlFormatter(style='pastie', nobackground=True) +formatter = HtmlFormatter(style='monokai', nobackground=True) try: lexer = guess_lexer_for_filename(filename, data) diff --git a/font.ttf b/font.ttf Binary files differnew file mode 100644 index 0000000..a646cc8 --- /dev/null +++ b/font.ttf @@ -0,0 +1,169 @@ +#define USE_THE_REPOSITORY_VARIABLE + +#include "cgit.h" +#include "html.h" +#include "ui-shared.h" +#include "ui-tree.h" +#include <string.h> +#include <sys/stat.h> + +/* Mapping of file extensions to languages */ +struct lang_extension { + const char *ext; + const char *lang; +}; + +static const struct lang_extension lang_map[] = {{"c", "C"}, + {"h", "C"}, + {"js", "JavaScript"}, + {"jsx", "JavaScript"}, + {"py", "Python"}, + {"go", "Go"}, + {"rs", "Rust"}, + {"rb", "Ruby"}, + {"java", "Java"}, + {"ts", "TypeScript"}, + {"tsx", "TypeScript"}, + {"cpp", "C++"}, + {"cc", "C++"}, + {"cxx", "C++"}, + {"cs", "C#"}, + {"php", "PHP"}, + {"sh", "Shell"}, + {"bash", "Shell"}, + {"lua", "Lua"}, + {"vim", "VimL"}, + {"clj", "Clojure"}, + {"scala", "Scala"}, + {"kt", "Kotlin"}, + {"swift", "Swift"}, + {"m", "Objective-C"}, + {"pl", "Perl"}, + {"r", "R"}, + {"sql", "SQL"}, + {"html", "HTML"}, + {"htm", "HTML"}, + {"css", "CSS"}, + {"scss", "SCSS"}, + {"json", "JSON"}, + {"yaml", "YAML"}, + {"yml", "YAML"}, + {"md", "Markdown"}, + {"rst", "ReStructuredText"}, + {NULL, NULL}}; + +struct lang_count { + const char *lang; + int count; +}; + +struct lang_detect_context { + struct lang_count counts[100]; + int count_nr; + int total_files; + int max_count; + const char *primary_lang; +}; + +static const char *get_lang_from_ext(const char *filename) { + const char *ext = strrchr(filename, '.'); + if (!ext || ext == filename) + return NULL; + + ext++; /* skip the dot */ + + for (int i = 0; lang_map[i].ext; i++) { + if (!strcasecmp(ext, lang_map[i].ext)) + return lang_map[i].lang; + } + return NULL; +} + +static void count_language(struct lang_detect_context *ctx, const char *lang) { + int i, found = 0; + + if (!lang) + return; + + ctx->total_files++; + + /* Find or add language in counts */ + for (i = 0; i < ctx->count_nr; i++) { + if (!strcmp(ctx->counts[i].lang, lang)) { + ctx->counts[i].count++; + if (ctx->counts[i].count > ctx->max_count) { + ctx->max_count = ctx->counts[i].count; + ctx->primary_lang = ctx->counts[i].lang; + } + found = 1; + break; + } + } + + if (!found && ctx->count_nr < 100) { + ctx->counts[ctx->count_nr].lang = lang; + ctx->counts[ctx->count_nr].count = 1; + if (1 > ctx->max_count) { + ctx->max_count = 1; + ctx->primary_lang = lang; + } + ctx->count_nr++; + } +} + +static int count_files_cb(const struct object_id *oid, struct strbuf *base, + const char *pathname, unsigned mode, void *cbdata) { + struct lang_detect_context *ctx = cbdata; + const char *lang; + + /* Skip directories */ + if (S_ISDIR(mode)) + return READ_TREE_RECURSIVE; + + /* Skip hidden files */ + if (pathname[0] == '.') + return 0; + + lang = get_lang_from_ext(pathname); + count_language(ctx, lang); + + return 0; +} + +void detect_repo_languages(struct cgit_repo *repo) { + struct object_id oid; + struct commit *commit; + struct tree *tree; + struct pathspec paths = {.nr = 0}; + struct lang_detect_context ctx; + + if (!repo->defbranch) + return; + + memset(&ctx, 0, sizeof(ctx)); + + /* Get the commit for the default branch */ + if (repo_get_oid(the_repository, repo->defbranch, &oid)) + return; + + commit = lookup_commit_reference(the_repository, &oid); + if (!commit) + return; + + if (repo_parse_commit(the_repository, commit)) + return; + + tree = repo_get_commit_tree(the_repository, commit); + if (!tree) + return; + + /* Walk the tree and count file extensions */ + read_tree(the_repository, tree, &paths, count_files_cb, &ctx); + + /* Store results in repo */ + if (ctx.primary_lang) { + repo->primary_lang = xstrdup(ctx.primary_lang); + repo->lang_confidence = + ctx.total_files > 0 ? (100 * ctx.max_count) / ctx.total_files : 0; + } +} @@ -0,0 +1,6 @@ +#pragma once + +#include "cgit.h" +#include "ui-shared.h" + +void detect_repo_languages(struct cgit_repo *repo); @@ -34,7 +34,7 @@ int chk_non_negative(int result, char *msg) return result; } -char *cgit_default_repo_desc = "[no description]"; +char *cgit_default_repo_desc = ""; struct cgit_repo *cgit_add_repo(const char *url) { struct cgit_repo *ret; @@ -82,6 +82,8 @@ struct cgit_repo *cgit_add_repo(const char *url) ret->clone_url = ctx.cfg.clone_url; ret->submodules.strdup_strings = 1; ret->hide = ret->ignore = 0; + ret->primary_lang = NULL; + ret->lang_confidence = 0; return ret; } diff --git a/ui-repolist.c b/ui-repolist.c index d12e3dd..59a4fbb 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -6,374 +6,369 @@ * (see COPYING for full license text) */ -#include "cgit.h" +#define USE_THE_REPOSITORY_VARIABLE + #include "ui-repolist.h" +#include "cgit.h" #include "html.h" +#include "lang.h" #include "ui-shared.h" -static time_t read_agefile(const char *path) -{ - time_t result; - size_t size; - char *buf = NULL; - struct strbuf date_buf = STRBUF_INIT; +static time_t read_agefile(const char *path) { + time_t result; + size_t size; + char *buf = NULL; + struct strbuf date_buf = STRBUF_INIT; - if (readfile(path, &buf, &size)) { - free(buf); - return 0; - } + if (readfile(path, &buf, &size)) { + free(buf); + return 0; + } - if (parse_date(buf, &date_buf) == 0) - result = strtoul(date_buf.buf, NULL, 10); - else - result = 0; - free(buf); - strbuf_release(&date_buf); - return result; + if (parse_date(buf, &date_buf) == 0) + result = strtoul(date_buf.buf, NULL, 10); + else + result = 0; + free(buf); + strbuf_release(&date_buf); + return result; } -static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) -{ - struct strbuf path = STRBUF_INIT; - struct stat s; - struct cgit_repo *r = (struct cgit_repo *)repo; +static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) { + struct strbuf path = STRBUF_INIT; + struct stat s; + struct cgit_repo *r = (struct cgit_repo *)repo; - if (repo->mtime != -1) { - *mtime = repo->mtime; - return 1; - } - strbuf_addf(&path, "%s/%s", repo->path, ctx.cfg.agefile); - if (stat(path.buf, &s) == 0) { - *mtime = read_agefile(path.buf); - if (*mtime) { - r->mtime = *mtime; - goto end; - } - } + if (repo->mtime != -1) { + *mtime = repo->mtime; + return 1; + } + strbuf_addf(&path, "%s/%s", repo->path, ctx.cfg.agefile); + if (stat(path.buf, &s) == 0) { + *mtime = read_agefile(path.buf); + if (*mtime) { + r->mtime = *mtime; + goto end; + } + } - strbuf_reset(&path); - strbuf_addf(&path, "%s/refs/heads/%s", repo->path, - repo->defbranch ? repo->defbranch : "master"); - if (stat(path.buf, &s) == 0) { - *mtime = s.st_mtime; - r->mtime = *mtime; - goto end; - } + strbuf_reset(&path); + strbuf_addf(&path, "%s/refs/heads/%s", repo->path, + repo->defbranch ? repo->defbranch : "master"); + if (stat(path.buf, &s) == 0) { + *mtime = s.st_mtime; + r->mtime = *mtime; + goto end; + } - strbuf_reset(&path); - strbuf_addf(&path, "%s/%s", repo->path, "packed-refs"); - if (stat(path.buf, &s) == 0) { - *mtime = s.st_mtime; - r->mtime = *mtime; - goto end; - } + strbuf_reset(&path); + strbuf_addf(&path, "%s/%s", repo->path, "packed-refs"); + if (stat(path.buf, &s) == 0) { + *mtime = s.st_mtime; + r->mtime = *mtime; + goto end; + } - *mtime = 0; - r->mtime = *mtime; + *mtime = 0; + r->mtime = *mtime; end: - strbuf_release(&path); - return (r->mtime != 0); + strbuf_release(&path); + return (r->mtime != 0); } -static void print_modtime(struct cgit_repo *repo) -{ - time_t t; - if (get_repo_modtime(repo, &t)) - cgit_print_age(t, 0, -1); +static void print_modtime(struct cgit_repo *repo) { + time_t t; + if (get_repo_modtime(repo, &t)) + cgit_print_age(t, 0, -1); } -static int is_match(struct cgit_repo *repo) -{ - if (!ctx.qry.search) - return 1; - if (repo->url && strcasestr(repo->url, ctx.qry.search)) - return 1; - if (repo->name && strcasestr(repo->name, ctx.qry.search)) - return 1; - if (repo->desc && strcasestr(repo->desc, ctx.qry.search)) - return 1; - if (repo->owner && strcasestr(repo->owner, ctx.qry.search)) - return 1; - return 0; +static int is_match(struct cgit_repo *repo) { + if (!ctx.qry.search) + return 1; + if (repo->url && strcasestr(repo->url, ctx.qry.search)) + return 1; + if (repo->name && strcasestr(repo->name, ctx.qry.search)) + return 1; + if (repo->desc && strcasestr(repo->desc, ctx.qry.search)) + return 1; + if (repo->owner && strcasestr(repo->owner, ctx.qry.search)) + return 1; + return 0; } -static int is_in_url(struct cgit_repo *repo) -{ - if (!ctx.qry.url) - return 1; - if (repo->url && starts_with(repo->url, ctx.qry.url)) - return 1; - return 0; +static int is_in_url(struct cgit_repo *repo) { + if (!ctx.qry.url) + return 1; + if (repo->url && starts_with(repo->url, ctx.qry.url)) + return 1; + return 0; } -static int is_visible(struct cgit_repo *repo) -{ - if (repo->hide || repo->ignore) - return 0; - if (!(is_match(repo) && is_in_url(repo))) - return 0; - return 1; +static int is_visible(struct cgit_repo *repo) { + if (repo->hide || repo->ignore) + return 0; + if (!(is_match(repo) && is_in_url(repo))) + return 0; + return 1; } -static int any_repos_visible(void) -{ - int i; +static int any_repos_visible(void) { + int i; - for (i = 0; i < cgit_repolist.count; i++) { - if (is_visible(&cgit_repolist.repos[i])) - return 1; - } - return 0; + for (i = 0; i < cgit_repolist.count; i++) { + if (is_visible(&cgit_repolist.repos[i])) + return 1; + } + return 0; } -static void print_sort_header(const char *title, const char *sort) -{ - char *currenturl = cgit_currenturl(); - html("<th class='left'><a href='"); - html_attr(currenturl); - htmlf("?s=%s", sort); - if (ctx.qry.search) { - html("&q="); - html_url_arg(ctx.qry.search); - } - htmlf("'>%s</a></th>", title); - free(currenturl); +static void print_sort_header(const char *title, const char *sort) { + char *currenturl = cgit_currenturl(); + html("<th class='left'><a href='"); + html_attr(currenturl); + htmlf("?s=%s", sort); + if (ctx.qry.search) { + html("&q="); + html_url_arg(ctx.qry.search); + } + htmlf("'>%s</a></th>", title); + free(currenturl); } -static void print_header(void) -{ - html("<tr class='nohover'>"); - print_sort_header("Name", "name"); - print_sort_header("Description", "desc"); - if (ctx.cfg.enable_index_owner) - print_sort_header("Owner", "owner"); - print_sort_header("Idle", "idle"); - if (ctx.cfg.enable_index_links) - html("<th class='left'>Links</th>"); - html("</tr>\n"); +static void print_header(void) { + html("<tr class='nohover'>"); + print_sort_header("Name", "name"); + print_sort_header("Description", "desc"); + // print_sort_header("Language", "name"); + if (ctx.cfg.enable_index_owner) + print_sort_header("Owner", "owner"); + print_sort_header("Idle", "idle"); + if (ctx.cfg.enable_index_links) + html("<th class='left'>Links</th>"); + html("</tr>\n"); } - -static void print_pager(int items, int pagelen, char *search, char *sort) -{ - int i, ofs; - char *class = NULL; - html("<ul class='pager'>"); - for (i = 0, ofs = 0; ofs < items; i++, ofs = i * pagelen) { - class = (ctx.qry.ofs == ofs) ? "current" : NULL; - html("<li>"); - cgit_index_link(fmt("[%d]", i + 1), fmt("Page %d", i + 1), - class, search, sort, ofs, 0); - html("</li>"); - } - html("</ul>"); +static void print_pager(int items, int pagelen, char *search, char *sort) { + int i, ofs; + char *class = NULL; + html("<ul class='pager'>"); + for (i = 0, ofs = 0; ofs < items; i++, ofs = i * pagelen) { + class = (ctx.qry.ofs == ofs) ? "current" : NULL; + html("<li>"); + cgit_index_link(fmt("[%d]", i + 1), fmt("Page %d", i + 1), class, search, + sort, ofs, 0); + html("</li>"); + } + html("</ul>"); } -static int cmp(const char *s1, const char *s2) -{ - if (s1 && s2) { - if (ctx.cfg.case_sensitive_sort) - return strcmp(s1, s2); - else - return strcasecmp(s1, s2); - } - if (s1 && !s2) - return -1; - if (s2 && !s1) - return 1; - return 0; +static int cmp(const char *s1, const char *s2) { + if (s1 && s2) { + if (ctx.cfg.case_sensitive_sort) + return strcmp(s1, s2); + else + return strcasecmp(s1, s2); + } + if (s1 && !s2) + return -1; + if (s2 && !s1) + return 1; + return 0; } -static int sort_name(const void *a, const void *b) -{ - const struct cgit_repo *r1 = a; - const struct cgit_repo *r2 = b; +static int sort_name(const void *a, const void *b) { + const struct cgit_repo *r1 = a; + const struct cgit_repo *r2 = b; - return cmp(r1->name, r2->name); + return cmp(r1->name, r2->name); } -static int sort_desc(const void *a, const void *b) -{ - const struct cgit_repo *r1 = a; - const struct cgit_repo *r2 = b; +static int sort_desc(const void *a, const void *b) { + const struct cgit_repo *r1 = a; + const struct cgit_repo *r2 = b; - return cmp(r1->desc, r2->desc); + return cmp(r1->desc, r2->desc); } -static int sort_owner(const void *a, const void *b) -{ - const struct cgit_repo *r1 = a; - const struct cgit_repo *r2 = b; +static int sort_owner(const void *a, const void *b) { + const struct cgit_repo *r1 = a; + const struct cgit_repo *r2 = b; - return cmp(r1->owner, r2->owner); + return cmp(r1->owner, r2->owner); } -static int sort_idle(const void *a, const void *b) -{ - const struct cgit_repo *r1 = a; - const struct cgit_repo *r2 = b; - time_t t1, t2; +static int sort_idle(const void *a, const void *b) { + const struct cgit_repo *r1 = a; + const struct cgit_repo *r2 = b; + time_t t1, t2; - t1 = t2 = 0; - get_repo_modtime(r1, &t1); - get_repo_modtime(r2, &t2); - return t2 - t1; + t1 = t2 = 0; + get_repo_modtime(r1, &t1); + get_repo_modtime(r2, &t2); + return t2 - t1; } -static int sort_section(const void *a, const void *b) -{ - const struct cgit_repo *r1 = a; - const struct cgit_repo *r2 = b; - int result; +static int sort_section(const void *a, const void *b) { + const struct cgit_repo *r1 = a; + const struct cgit_repo *r2 = b; + int result; - result = cmp(r1->section, r2->section); - if (!result) { - if (!strcmp(ctx.cfg.repository_sort, "age")) - result = sort_idle(r1, r2); - if (!result) - result = cmp(r1->name, r2->name); - } - return result; + result = cmp(r1->section, r2->section); + if (!result) { + if (!strcmp(ctx.cfg.repository_sort, "age")) + result = sort_idle(r1, r2); + if (!result) + result = cmp(r1->name, r2->name); + } + return result; } struct sortcolumn { - const char *name; - int (*fn)(const void *a, const void *b); + const char *name; + int (*fn)(const void *a, const void *b); }; static const struct sortcolumn sortcolumn[] = { - {"section", sort_section}, - {"name", sort_name}, - {"desc", sort_desc}, - {"owner", sort_owner}, - {"idle", sort_idle}, - {NULL, NULL} -}; + {"section", sort_section}, {"name", sort_name}, {"desc", sort_desc}, + {"owner", sort_owner}, {"idle", sort_idle}, {NULL, NULL}}; -static int sort_repolist(char *field) -{ - const struct sortcolumn *column; +static int sort_repolist(char *field) { + const struct sortcolumn *column; - for (column = &sortcolumn[0]; column->name; column++) { - if (strcmp(field, column->name)) - continue; - qsort(cgit_repolist.repos, cgit_repolist.count, - sizeof(struct cgit_repo), column->fn); - return 1; - } - return 0; + for (column = &sortcolumn[0]; column->name; column++) { + if (strcmp(field, column->name)) + continue; + qsort(cgit_repolist.repos, cgit_repolist.count, sizeof(struct cgit_repo), + column->fn); + return 1; + } + return 0; } +void cgit_print_repolist(void) { + int i, columns = 3, hits = 0, header = 0; + char *last_section = NULL; + char *section; + char *repourl; + int sorted = 0; + + if (!any_repos_visible()) { + cgit_print_error_page(404, "Not found", "No repositories found"); + return; + } + + if (ctx.cfg.enable_index_links) + ++columns; + if (ctx.cfg.enable_index_owner) + ++columns; + + ctx.page.title = ctx.cfg.root_title; + cgit_print_http_headers(); + cgit_print_docstart(); + cgit_print_pageheader(); + + if (ctx.qry.sort) + sorted = sort_repolist(ctx.qry.sort); + else if (ctx.cfg.section_sort) + sort_repolist("section"); -void cgit_print_repolist(void) -{ - int i, columns = 3, hits = 0, header = 0; - char *last_section = NULL; - char *section; - char *repourl; - int sorted = 0; + html("<table summary='repository list' class='list nowrap'>"); + for (i = 0; i < cgit_repolist.count; i++) { + ctx.repo = &cgit_repolist.repos[i]; - if (!any_repos_visible()) { - cgit_print_error_page(404, "Not found", "No repositories found"); - return; - } + if (!is_visible(ctx.repo)) + continue; + hits++; + if (hits <= ctx.qry.ofs) + continue; + if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count) + continue; + if (!header++) + print_header(); - if (ctx.cfg.enable_index_links) - ++columns; - if (ctx.cfg.enable_index_owner) - ++columns; + section = ctx.repo->section; + if (section && !strcmp(section, "")) + section = NULL; + if (!sorted && ((last_section == NULL && section != NULL) || + (last_section != NULL && section == NULL) || + (last_section != NULL && section != NULL && + strcmp(section, last_section)))) { + htmlf( + "<tr class='nohover-highlight'><td colspan='%d' class='reposection'>", + columns); + html_txt(section); + html("</td></tr>"); + last_section = section; + } + htmlf("<tr><td class='%s'>", + !sorted && section ? "sublevel-repo" : "toplevel-repo"); + cgit_summary_link(ctx.repo->name, NULL, NULL, NULL); + html("</td><td>"); + repourl = cgit_repourl(ctx.repo->url); + html_link_open(repourl, NULL, NULL); + free(repourl); + if (html_ntxt(ctx.repo->desc, ctx.cfg.max_repodesc_len) < 0) + html("..."); + html_link_close(); + // html("</td><td>"); - ctx.page.title = ctx.cfg.root_title; - cgit_print_http_headers(); - cgit_print_docstart(); - cgit_print_pageheader(); + // // The important thing is that i tried. + // if (ctx.repo->primary_lang) { + // html_txt(ctx.repo->primary_lang); + // htmlf("%d%%", ctx.repo->lang_confidence); + // } else { + // htmlf("%p = %s", ctx.repo->primary_lang, ctx.repo->primary_lang); + // } - if (ctx.qry.sort) - sorted = sort_repolist(ctx.qry.sort); - else if (ctx.cfg.section_sort) - sort_repolist("section"); + html("</td><td>"); + if (ctx.cfg.enable_index_owner) { + if (ctx.repo->owner_filter) { + cgit_open_filter(ctx.repo->owner_filter); + html_txt(ctx.repo->owner); + cgit_close_filter(ctx.repo->owner_filter); + } else { + char *currenturl = cgit_currenturl(); + html("<a href='"); + html_attr(currenturl); + html("?q="); + html_url_arg(ctx.repo->owner); + html("'>"); + html_txt(ctx.repo->owner); + html("</a>"); + free(currenturl); + } + html("</td><td>"); + } + print_modtime(ctx.repo); + html("</td>"); + if (ctx.cfg.enable_index_links) { + html("<td>"); + cgit_summary_link("summary", NULL, "button", NULL); + cgit_log_link("log", NULL, "button", NULL, NULL, NULL, 0, NULL, NULL, + ctx.qry.showmsg, 0); + cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); + html("</td>"); + } + html("</tr>\n"); + } + html("</table>"); + if (hits > ctx.cfg.max_repo_count) + print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort); + html("<hr>"); + cgit_open_filter(ctx.cfg.about_filter, ctx.cfg.root_readme); + html_include(ctx.cfg.root_readme); + cgit_close_filter(ctx.cfg.about_filter); - html("<table summary='repository list' class='list nowrap'>"); - for (i = 0; i < cgit_repolist.count; i++) { - ctx.repo = &cgit_repolist.repos[i]; - if (!is_visible(ctx.repo)) - continue; - hits++; - if (hits <= ctx.qry.ofs) - continue; - if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count) - continue; - if (!header++) - print_header(); - section = ctx.repo->section; - if (section && !strcmp(section, "")) - section = NULL; - if (!sorted && - ((last_section == NULL && section != NULL) || - (last_section != NULL && section == NULL) || - (last_section != NULL && section != NULL && - strcmp(section, last_section)))) { - htmlf("<tr class='nohover-highlight'><td colspan='%d' class='reposection'>", - columns); - html_txt(section); - html("</td></tr>"); - last_section = section; - } - htmlf("<tr><td class='%s'>", - !sorted && section ? "sublevel-repo" : "toplevel-repo"); - cgit_summary_link(ctx.repo->name, NULL, NULL, NULL); - html("</td><td>"); - repourl = cgit_repourl(ctx.repo->url); - html_link_open(repourl, NULL, NULL); - free(repourl); - if (html_ntxt(ctx.repo->desc, ctx.cfg.max_repodesc_len) < 0) - html("..."); - html_link_close(); - html("</td><td>"); - if (ctx.cfg.enable_index_owner) { - if (ctx.repo->owner_filter) { - cgit_open_filter(ctx.repo->owner_filter); - html_txt(ctx.repo->owner); - cgit_close_filter(ctx.repo->owner_filter); - } else { - char *currenturl = cgit_currenturl(); - html("<a href='"); - html_attr(currenturl); - html("?q="); - html_url_arg(ctx.repo->owner); - html("'>"); - html_txt(ctx.repo->owner); - html("</a>"); - free(currenturl); - } - html("</td><td>"); - } - print_modtime(ctx.repo); - html("</td>"); - if (ctx.cfg.enable_index_links) { - html("<td>"); - cgit_summary_link("summary", NULL, "button", NULL); - cgit_log_link("log", NULL, "button", NULL, NULL, NULL, - 0, NULL, NULL, ctx.qry.showmsg, 0); - cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); - html("</td>"); - } - html("</tr>\n"); - } - html("</table>"); - if (hits > ctx.cfg.max_repo_count) - print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort); - cgit_print_docend(); + cgit_print_docend(); } -void cgit_print_site_readme(void) -{ - cgit_print_layout_start(); - if (!ctx.cfg.root_readme) - goto done; - cgit_open_filter(ctx.cfg.about_filter, ctx.cfg.root_readme); - html_include(ctx.cfg.root_readme); - cgit_close_filter(ctx.cfg.about_filter); +void cgit_print_site_readme(void) { + cgit_print_layout_start(); + if (!ctx.cfg.root_readme) + goto done; + cgit_open_filter(ctx.cfg.about_filter, ctx.cfg.root_readme); + html_include(ctx.cfg.root_readme); + cgit_close_filter(ctx.cfg.about_filter); done: - cgit_print_layout_end(); + cgit_print_layout_end(); } diff --git a/ui-shared.c b/ui-shared.c index df52a9b..dffa206 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -877,8 +877,7 @@ void cgit_print_docend(void) if (ctx.cfg.footer) html_include(ctx.cfg.footer); else { - htmlf("<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit %s</a> " - "(<a href='https://git-scm.com/'>git %s</a>) at ", cgit_version, git_version_string); + htmlf("<div class='footer'>generated by <a href='https://git.spelis.projnull.eu/spelis/cgit'>cgit</a> (<a href='https://git.zx2c4.com/cgit/about/'>orig</a>) "); html_txt(show_date(time(NULL), 0, cgit_date_mode(DATE_ISO8601))); html("</div>\n"); } @@ -1078,6 +1077,7 @@ static void print_header(void) html("</td></tr></table>\n"); } + void cgit_print_pageheader(void) { html("<div id='cgit'>"); @@ -1138,11 +1138,6 @@ void cgit_print_pageheader(void) html("</form>\n"); } else if (ctx.env.authenticated) { char *currenturl = cgit_currenturl(); - site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1); - if (ctx.cfg.root_readme) - site_link("about", "about", NULL, hc("about"), - NULL, NULL, 0, 1); - html("</td><td class='form'>"); html("<form method='get' action='"); html_attr(currenturl); html("'>\n"); |
