diff --git a/app/models/__init__.py b/app/models/__init__.py index 257039f..7bf9ede 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -61,6 +61,18 @@ def url(**kwargs): """ return cherrypy.request.base + routes.url_for(**kwargs) +_MAX_URL_CHARS = 40 + +_HTTP_RE = re.compile(r"^https?://") + +def nice_url(url): + """Returns a human-readable version of URL. + + This removes the scheme and ellipsizes if necessary. It returns None if the + url is None.""" + if url is None: return None + return ellipsize(_HTTP_RE.sub("", url), _MAX_URL_CHARS) + def relative_date(date): """Construct a human-friendly relative date string like "2 hours ago". diff --git a/app/models/package.py b/app/models/package.py index 16649de..3e07516 100644 --- a/app/models/package.py +++ b/app/models/package.py @@ -70,12 +70,22 @@ def homepage(self): if self.latest_version is None: return None return self.latest_version.pubspec.get('homepage') + @property + def nice_homepage(self): + """The human-readable homepage URL for the package.""" + return models.nice_url(self.homepage) + @property def documentation(self): """The documentation URL for the package, or None.""" if self.latest_version is None: return None return self.latest_version.documentation + @property + def nice_documentation(self): + """The human-readable documentation URL for the package.""" + return models.nice_url(self.documentation) + @property def authors_title(self): """The title for the authors list of the package.""" diff --git a/app/views/packages/show.mustache b/app/views/packages/show.mustache index 0e27ae9..18e6a31 100644 --- a/app/views/packages/show.mustache +++ b/app/views/packages/show.mustache @@ -123,12 +123,12 @@ $ pub install {{#package.homepage}}

Homepage

-

{{package.homepage}}

+

{{package.nice_homepage}}

{{/package.homepage}} {{#package.documentation}}

Documentation

-

{{package.documentation}}

+

{{package.nice_documentation}}

{{/package.documentation}}

{{package.uploaders_title}}