<div dir="ltr">I tried to apply your patch to v1.2.1-24-ge1ad15d (after having removed lines 2 & 3), I get:<div>git apply --verbose ../default-pages.patch<br><div>error: corrupt patch at line 169<br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Aug 15, 2019 at 2:50 PM Naïm Favier <<a href="mailto:fnaim42@gmail.com">fnaim42@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">It would be nice to be able to configure the default page to use for the<br>
root site and repositories. For example, it might make more sense to<br>
have "about" or "tree" as the default landing page for certain repos,<br>
instead of the default "summary".<br>
<br>
This patch introduces the following configuration settings:<br>
- "root-default-page": sets the default page for the root site<br>
(defaults to "repolist")<br>
- "repo.default-page": sets the default page for individual repos<br>
(defaults to "summary")<br>
- "default-page": global default value for "repo.default-page"<br>
<br>
The following accessory changes were required to make this work:<br>
- the "index" tab link on root pages and the "summary" tab link on repo<br>
pages now explicitly point to their respective targets instead of<br>
pointing to the site/repo root<br>
- trying to access the "about" page on a repository without one results<br>
in being redirected to the "summary" page explicitly<br>
<br>
Signed-off-by: Naïm Favier <<a href="mailto:fnaim42@gmail.com" target="_blank">fnaim42@gmail.com</a>><br>
---<br>
Hope this is better, I went all the way and added a per-repo setting too.<br>
<br>
cgit.c | 10 ++++++++++<br>
cgit.h | 3 +++<br>
cgitrc.5.txt | 14 ++++++++++++++<br>
cmd.c | 18 +++++++++---------<br>
ui-repolist.c | 2 +-<br>
ui-shared.c | 12 +++++++++---<br>
ui-shared.h | 2 ++<br>
7 files changed, 48 insertions(+), 13 deletions(-)<br>
<br>
diff --git a/cgit.c b/cgit.c<br>
index 2910d4b..89a5ba9 100644<br>
--- a/cgit.c<br>
+++ b/cgit.c<br>
@@ -46,6 +46,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va<br>
repo->homepage = xstrdup(value);<br>
else if (!strcmp(name, "defbranch"))<br>
repo->defbranch = xstrdup(value);<br>
+ else if (!strcmp(name, "default-page"))<br>
+ repo->default_page = xstrdup(value);<br>
else if (!strcmp(name, "extra-head-content"))<br>
repo->extra_head_content = xstrdup(value);<br>
else if (!strcmp(name, "snapshots"))<br>
@@ -131,6 +133,8 @@ static void config_cb(const char *name, const char *value)<br>
ctx.cfg.root_desc = xstrdup(value);<br>
else if (!strcmp(name, "root-readme"))<br>
ctx.cfg.root_readme = xstrdup(value);<br>
+ else if (!strcmp(name, "root-default-page"))<br>
+ ctx.cfg.root_default_page = xstrdup(value);<br>
else if (!strcmp(name, "css"))<br>
ctx.cfg.css = xstrdup(value);<br>
else if (!strcmp(name, "favicon"))<br>
@@ -145,6 +149,8 @@ static void config_cb(const char *name, const char *value)<br>
ctx.cfg.logo = xstrdup(value);<br>
else if (!strcmp(name, "logo-link"))<br>
ctx.cfg.logo_link = xstrdup(value);<br>
+ else if (!strcmp(name, "default-page"))<br>
+ ctx.cfg.default_page = xstrdup(value);<br>
else if (!strcmp(name, "module-link"))<br>
ctx.cfg.module_link = xstrdup(value);<br>
else if (!strcmp(name, "strict-export"))<br>
@@ -367,6 +373,7 @@ static void prepare_context(void)<br>
ctx.cfg.branch_sort = 0;<br>
ctx.cfg.commit_sort = 0;<br>
ctx.cfg.css = "/cgit.css";<br>
+ ctx.cfg.default_page= "summary";<br>
ctx.cfg.logo = "/cgit.png";<br>
ctx.cfg.favicon = "/favicon.ico";<br>
ctx.cfg.local_time = 0;<br>
@@ -387,6 +394,7 @@ static void prepare_context(void)<br>
ctx.cfg.robots = "index, nofollow";<br>
ctx.cfg.root_title = "Git repository browser";<br>
ctx.cfg.root_desc = "a fast webinterface for the git dscm";<br>
+ ctx.cfg.root_default_page = "repolist";<br>
ctx.cfg.scan_hidden_path = 0;<br>
ctx.cfg.script_name = CGIT_SCRIPT_NAME;<br>
ctx.cfg.section = "";<br>
@@ -801,6 +809,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)<br>
}<br>
if (repo->defbranch)<br>
fprintf(f, "repo.defbranch=%s\n", repo->defbranch);<br>
+ if (repo->default_page)<br>
+ fprintf(f, "repo.default-page=%s\n", repo->default_page);<br>
if (repo->extra_head_content)<br>
fprintf(f, "repo.extra-head-content=%s\n", repo->extra_head_content);<br>
if (repo->module_link)<br>
diff --git a/cgit.h b/cgit.h<br>
index 7ec46b4..06024ea 100644<br>
--- a/cgit.h<br>
+++ b/cgit.h<br>
@@ -86,6 +86,7 @@ struct cgit_repo {<br>
char *owner;<br>
char *homepage;<br>
char *defbranch;<br>
+ char *default_page;<br>
char *module_link;<br>
struct string_list readme;<br>
char *section;<br>
@@ -196,6 +197,7 @@ struct cgit_config {<br>
char *clone_prefix;<br>
char *clone_url;<br>
char *css;<br>
+ char *default_page;<br>
char *favicon;<br>
char *footer;<br>
char *head_include;<br>
@@ -210,6 +212,7 @@ struct cgit_config {<br>
char *root_title;<br>
char *root_desc;<br>
char *root_readme;<br>
+ char *root_default_page;<br>
char *script_name;<br>
char *section;<br>
char *repository_sort;<br>
diff --git a/cgitrc.5.txt b/cgitrc.5.txt<br>
index ba77826..2e59180 100644<br>
--- a/cgitrc.5.txt<br>
+++ b/cgitrc.5.txt<br>
@@ -128,6 +128,12 @@ css::<br>
Url which specifies the css document to include in all cgit pages.<br>
Default value: "/cgit.css".<br>
<br>
+default-page::<br>
+ Specifies the default page for repositories. This setting is only used<br>
+ if `repo.default-page` is unspecified. Possible values: "about",<br>
+ "summary", "refs", "log", "tree", "commit", "diff", "stats". Default<br>
+ value: "summary".<br>
+<br>
email-filter::<br>
Specifies a command which will be invoked to format names and email<br>
address of committers, authors, and taggers, as represented in various<br>
@@ -352,6 +358,10 @@ robots::<br>
Text used as content for the "robots" meta-tag. Default value:<br>
"index, nofollow".<br>
<br>
+root-default-page::<br>
+ Specifies the default root page. Possible values are "repolist" and<br>
+ "about". Default value: "repolist".<br>
+<br>
root-desc::<br>
Text printed below the heading on the repository index page. Default<br>
value: "a fast webinterface for the git dscm".<br>
@@ -472,6 +482,10 @@ repo.commit-sort::<br>
ordering. If unset, the default ordering of "git log" is used. Default<br>
value: unset.<br>
<br>
+repo.default-page::<br>
+ Specifies the default page for the repository. Default value: global<br>
+ default-page.<br>
+<br>
repo.defbranch::<br>
The name of the default branch for this repository. If no such branch<br>
exists in the repository, the first branch name (when sorted) is used<br>
diff --git a/cmd.c b/cmd.c<br>
index bf6d8f5..9eda2c7 100644<br>
--- a/cmd.c<br>
+++ b/cmd.c<br>
@@ -51,13 +51,10 @@ static void about_fn(void)<br>
free(redirect);<br>
} else if (ctx.repo-><a href="http://readme.nr" rel="noreferrer" target="_blank">readme.nr</a>)<br>
cgit_print_repo_readme(ctx.qry.path);<br>
- else if (ctx.repo->homepage)<br>
- cgit_redirect(ctx.repo->homepage, false);<br>
else {<br>
- char *currenturl = cgit_currenturl();<br>
- char *redirect = fmtalloc("%s../", currenturl);<br>
+ char *redirect = fmtalloc("%s%s/summary/",<br>
+ ctx.cfg.virtual_root, ctx.repo->url);<br>
cgit_redirect(redirect, false);<br>
- free(currenturl);<br>
free(redirect);<br>
}<br>
} else<br>
@@ -195,10 +192,13 @@ struct cgit_cmd *cgit_get_cmd(void)<br>
int i;<br>
<br>
if (<a href="http://ctx.qry.page" rel="noreferrer" target="_blank">ctx.qry.page</a> == NULL) {<br>
- if (ctx.repo)<br>
- <a href="http://ctx.qry.page" rel="noreferrer" target="_blank">ctx.qry.page</a> = "summary";<br>
- else<br>
- <a href="http://ctx.qry.page" rel="noreferrer" target="_blank">ctx.qry.page</a> = "repolist";<br>
+ if (ctx.repo) {<br>
+ if (ctx.repo->default_page && *ctx.repo->default_page)<br>
+ <a href="http://ctx.qry.page" rel="noreferrer" target="_blank">ctx.qry.page</a> = ctx.repo->default_page;<br>
+ else<br>
+ <a href="http://ctx.qry.page" rel="noreferrer" target="_blank">ctx.qry.page</a> = ctx.cfg.default_page;<br>
+ } else<br>
+ <a href="http://ctx.qry.page" rel="noreferrer" target="_blank">ctx.qry.page</a> = ctx.cfg.root_default_page;<br>
}<br>
<br>
for (i = 0; i < sizeof(cmds)/sizeof(*cmds); i++)<br>
diff --git a/ui-repolist.c b/ui-repolist.c<br>
index 7cf7638..a49f457 100644<br>
--- a/ui-repolist.c<br>
+++ b/ui-repolist.c<br>
@@ -321,7 +321,7 @@ void cgit_print_repolist(void)<br>
}<br>
htmlf("<tr><td class='%s'>",<br>
!sorted && section ? "sublevel-repo" : "toplevel-repo");<br>
- cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);<br>
+ cgit_repo_link(ctx.repo->name, ctx.repo->name, NULL, NULL);<br>
html("</td><td>");<br>
repourl = cgit_repourl(ctx.repo->url);<br>
html_link_open(repourl, NULL, NULL);<br>
diff --git a/ui-shared.c b/ui-shared.c<br>
index d2358f2..bb3050e 100644<br>
--- a/ui-shared.c<br>
+++ b/ui-shared.c<br>
@@ -327,10 +327,16 @@ static void reporevlink(const char *page, const char *name, const char *title,<br>
html("</a>");<br>
}<br>
<br>
+void cgit_repo_link(const char *name, const char *title, const char *class,<br>
+ const char *head)<br>
+{<br>
+ reporevlink(NULL, name, title, class, head, NULL, NULL);<br>
+}<br>
+<br>
void cgit_summary_link(const char *name, const char *title, const char *class,<br>
const char *head)<br>
{<br>
- reporevlink(NULL, name, title, class, head, NULL, NULL);<br>
+ reporevlink("summary", name, title, class, head, NULL, NULL);<br>
}<br>
<br>
void cgit_tag_link(const char *name, const char *title, const char *class,<br>
@@ -994,7 +1000,7 @@ static void print_header(void)<br>
if (ctx.repo) {<br>
cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);<br>
html(" : ");<br>
- cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);<br>
+ cgit_repo_link(ctx.repo->name, ctx.repo->name, NULL, NULL);<br>
if (ctx.env.authenticated) {<br>
html("</td><td class='form'>");<br>
html("<form method='get'>\n");<br>
@@ -1083,7 +1089,7 @@ void cgit_print_pageheader(void)<br>
html("</form>\n");<br>
} else if (ctx.env.authenticated) {<br>
char *currenturl = cgit_currenturl();<br>
- site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1);<br>
+ site_link("repolist", "index", NULL, hc("repolist"), NULL, NULL, 0, 1);<br>
if (ctx.cfg.root_readme)<br>
site_link("about", "about", NULL, hc("about"),<br>
NULL, NULL, 0, 1);<br>
diff --git a/ui-shared.h b/ui-shared.h<br>
index 6964873..4d14858 100644<br>
--- a/ui-shared.h<br>
+++ b/ui-shared.h<br>
@@ -17,6 +17,8 @@ extern void cgit_add_clone_urls(void (*fn)(const char *));<br>
<br>
extern void cgit_index_link(const char *name, const char *title,<br>
const char *class, const char *pattern, const char *sort, int ofs, int always_root);<br>
+extern void cgit_repo_link(const char *name, const char *title,<br>
+ const char *class, const char *head);<br>
extern void cgit_summary_link(const char *name, const char *title,<br>
const char *class, const char *head);<br>
extern void cgit_tag_link(const char *name, const char *title,<br>
--<br>
2.22.0<br>
<br>
_______________________________________________<br>
CGit mailing list<br>
<a href="mailto:CGit@lists.zx2c4.com" target="_blank">CGit@lists.zx2c4.com</a><br>
<a href="https://lists.zx2c4.com/mailman/listinfo/cgit" rel="noreferrer" target="_blank">https://lists.zx2c4.com/mailman/listinfo/cgit</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">Jean-Christophe</div>