mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-23 06:22:24 +01:00
Make OpenGraph URLs absolute
This commit is contained in:
parent
e94bd9b845
commit
57e7cbfd09
@ -578,11 +578,23 @@ class Package(db.Model):
|
|||||||
screenshot = self.screenshots.filter_by(approved=True).order_by(db.asc(PackageScreenshot.id)).first()
|
screenshot = self.screenshots.filter_by(approved=True).order_by(db.asc(PackageScreenshot.id)).first()
|
||||||
return screenshot.getThumbnailURL(level) if screenshot is not None else None
|
return screenshot.getThumbnailURL(level) if screenshot is not None else None
|
||||||
|
|
||||||
def getMainScreenshotURL(self):
|
def getMainScreenshotURL(self, absolute=False):
|
||||||
screenshot = self.screenshots.filter_by(approved=True).order_by(db.asc(PackageScreenshot.id)).first()
|
screenshot = self.screenshots.filter_by(approved=True).order_by(db.asc(PackageScreenshot.id)).first()
|
||||||
return screenshot.url if screenshot is not None else None
|
if screenshot is None:
|
||||||
|
return None
|
||||||
|
|
||||||
def getDetailsURL(self):
|
if absolute:
|
||||||
|
from app.utils import abs_url
|
||||||
|
return abs_url(screenshot.url)
|
||||||
|
else:
|
||||||
|
return screenshot.url
|
||||||
|
|
||||||
|
def getDetailsURL(self, absolute=False):
|
||||||
|
if absolute:
|
||||||
|
from app.utils import abs_url_for
|
||||||
|
return abs_url_for("packages.view",
|
||||||
|
author=self.author.username, name=self.name)
|
||||||
|
else:
|
||||||
return url_for("packages.view",
|
return url_for("packages.view",
|
||||||
author=self.author.username, name=self.name)
|
author=self.author.username, name=self.name)
|
||||||
|
|
||||||
|
@ -10,9 +10,9 @@
|
|||||||
<meta name="og:title" content="{{ package.title }}"/>
|
<meta name="og:title" content="{{ package.title }}"/>
|
||||||
<meta name="og:description" content="{{ package.short_desc }}"/>
|
<meta name="og:description" content="{{ package.short_desc }}"/>
|
||||||
<meta name="description" content="{{ package.short_desc }}"/>
|
<meta name="description" content="{{ package.short_desc }}"/>
|
||||||
<meta name="og:url" content="{{ package.getDetailsURL() }}"/>
|
<meta name="og:url" content="{{ package.getDetailsURL(absolute=True) }}"/>
|
||||||
{% if package.getMainScreenshotURL() %}
|
{% if package.getMainScreenshotURL() %}
|
||||||
<meta name="og:image" content="{{ package.getMainScreenshotURL() }}"/>
|
<meta name="og:image" content="{{ package.getMainScreenshotURL(absolute=True) }}"/>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -21,11 +21,15 @@ from flask_login import login_user, logout_user
|
|||||||
from .models import *
|
from .models import *
|
||||||
from . import app
|
from . import app
|
||||||
import random, string, os, imghdr
|
import random, string, os, imghdr
|
||||||
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
def abs_url_for(path, **kwargs):
|
def abs_url_for(path, **kwargs):
|
||||||
scheme = "https" if app.config["BASE_URL"][:5] == "https" else "http"
|
scheme = "https" if app.config["BASE_URL"][:5] == "https" else "http"
|
||||||
return url_for(path, _external=True, _scheme=scheme, **kwargs)
|
return url_for(path, _external=True, _scheme=scheme, **kwargs)
|
||||||
|
|
||||||
|
def abs_url(path):
|
||||||
|
return urljoin(app.config["BASE_URL"], path)
|
||||||
|
|
||||||
def get_int_or_abort(v, default=None):
|
def get_int_or_abort(v, default=None):
|
||||||
try:
|
try:
|
||||||
return int(v or default)
|
return int(v or default)
|
||||||
|
Loading…
Reference in New Issue
Block a user