grim/hgwebplus

A few tweaks, mostly to http_clone_url

2020-11-02, Gary Kramlich
93741e95c979
Parents a8213ca40666
Children 208941cb10dd
A few tweaks, mostly to http_clone_url
--- a/src/hgwebplus.py Sun May 17 23:16:07 2020 -0500
+++ b/src/hgwebplus.py Mon Nov 02 21:19:10 2020 -0600
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with hgwebplus. If not, see <https://www.gnu.org/licenses/>.
+import os.path
import re
from hashlib import md5 as hashlib_md5
@@ -28,7 +29,7 @@
registrar,
templateutil
)
-from mercurial.hgweb import webutil, hgweb_mod
+from mercurial.hgweb import webutil, hgweb_mod, hgwebdir_mod
from mercurial.hgweb.common import paritygen
from urllib.parse import urlparse
@@ -253,8 +254,19 @@
"""
ui = context.resource(mapping, b'ui')
+ repo = context.resource(mapping, b'repo')
- return ui.config(b'web', b'http_clone_url', b'')
+ uri = ui.config(b'web', b'http_clone_url', b'')
+ if uri == b'':
+ base = ui.config(b'web', b'http_base_url', b'')
+
+ if base != '':
+ if base[-1] != b'/':
+ base += b'/'
+
+ return base + os.path.relpath(repo.root.decode('UTF-8')).encode()
+
+ return b''
def readme(context, mapping):
@@ -311,25 +323,18 @@
return ui.config(b'web', b'ssh_clone_url', b'')
-def sub_title(context, mapping):
- """ sub_title is a template keyword that outputs the configuration value of
- `web.sub_title`. Themes can use this as a secondary text to the title.
- """
+def dir_custom_templater(orig, self, req, nonce):
+ templater = orig(self, req, nonce)
- ui = context.resource(mapping, b'ui')
-
- return ui.config(b'web', b'sub_title', b'')
-
+ templatekeyword = registrar.templatekeyword(templater._proc._defaults)
-def title(context, mapping):
- """ title is a template keyword that outputs the configuration value of
- `web.title`. Themes can use this as the HTML title and else where on
- the pages.
- """
+ sub_title = lambda c, m: self.ui.config(b'web', b'sub_title', b'')
+ templatekeyword(b'sub_title', requires=())(sub_title)
- ui = context.resource(mapping, b'ui')
+ title = lambda c, m: self.ui.config(b'web', b'title', b'')
+ templatekeyword(b'title', requires=())(title)
- return ui.config(b'web', b'title', b'')
+ return templater
def repo_custom_templater(orig, self, req):
@@ -342,11 +347,15 @@
templatekeyword = registrar.templatekeyword(templater._proc._defaults)
- templatekeyword(b'http_clone_url', requires={b'ui'})(http_clone_url)
+ templatekeyword(b'http_clone_url', requires={b'ui', b'repo'})(http_clone_url)
templatekeyword(b'readme', requires={b'ctx', b'repo'})(readme)
- templatekeyword(b'ssh_clone_url', requires={b'ui'})(ssh_clone_url)
- templatekeyword(b'sub_title', requires={b'ui'})(sub_title)
- templatekeyword(b'title', requires={b'ui'})(title)
+ templatekeyword(b'ssh_clone_url', requires={b'ui', b'repo'})(ssh_clone_url)
+
+ sub_title = lambda c, m: self.config(b'web', b'sub_title', b'')
+ templatekeyword(b'sub_title', requires=())(sub_title)
+
+ title = lambda c, m: self.config(b'web', b'title', b'')
+ templatekeyword(b'title', requires=())(title)
return templater
@@ -355,7 +364,12 @@
extensions.wrapfunction(webutil, '_diffstattmplgen', _diffstattmplgen)
extensions.wrapfunction(webutil, '_diffsgen', _diffsgen)
- # this nasty but amazingly working hack is from av6
+ # these nasty but amazingly working hacks are from av6
+ extensions.wrapfunction(
+ hgwebdir_mod.hgwebdir,
+ 'templater',
+ dir_custom_templater,
+ )
extensions.wrapfunction(
hgweb_mod.requestcontext,
'templater',