diff options
Diffstat (limited to 'ui-shared.c')
-rw-r--r-- | ui-shared.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index e5c9a02..2547e43 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -1111,3 +1111,34 @@ void cgit_print_snapshot_links(const char *repo, const char *head, | |||
1111 | } | 1111 | } |
1112 | strbuf_release(&filename); | 1112 | strbuf_release(&filename); |
1113 | } | 1113 | } |
1114 | |||
1115 | void cgit_set_title_from_path(const char *path) | ||
1116 | { | ||
1117 | size_t path_len, path_index, path_last_end; | ||
1118 | char *new_title; | ||
1119 | |||
1120 | if (!path) | ||
1121 | return; | ||
1122 | |||
1123 | path_len = strlen(path); | ||
1124 | new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1); | ||
1125 | new_title[0] = '\0'; | ||
1126 | |||
1127 | for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) { | ||
1128 | if (path[path_index] == '/') { | ||
1129 | if (path_index == path_len - 1) { | ||
1130 | path_last_end = path_index - 1; | ||
1131 | continue; | ||
1132 | } | ||
1133 | strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1); | ||
1134 | strcat(new_title, "\\"); | ||
1135 | path_last_end = path_index; | ||
1136 | } | ||
1137 | } | ||
1138 | if (path_last_end) | ||
1139 | strncat(new_title, path, path_last_end); | ||
1140 | |||
1141 | strcat(new_title, " - "); | ||
1142 | strcat(new_title, ctx.page.title); | ||
1143 | ctx.page.title = new_title; | ||
1144 | } | ||