Skip to content

Commit

Permalink
Merge pull request #105 from zediious/0.3.1
Browse files Browse the repository at this point in the history
Changes for 0.3.1
  • Loading branch information
zediious authored Nov 6, 2023
2 parents 07802c8 + 42f99ff commit fb0c585
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 48 deletions.
81 changes: 52 additions & 29 deletions raptorWeb/raptormc/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

class Route:

def __init__(self, name, route_type, user=None, page=None) -> None:
def __init__(self, name, route_type, informative_text=None, user=None, page=None) -> None:
self.name: str = name
self.route_type: str = route_type
self.informative_text = informative_text
self.user: RaptorUser = user
self.page: Page = page

Expand All @@ -27,7 +28,8 @@ def __str__(self) -> str:
def check_route(request):
"""
Check all baked-in URLPatterns as well as
variations for created objects. Return True
variations for created objects. Return context
with OpenGraph information about the route
if the route exists, False if it does not.
"""
def _get_user_routes():
Expand Down Expand Up @@ -70,32 +72,53 @@ def _get_page_routes():
)
)

def _get_main_routes():
"""
Iterate current URLPatterns and create
Routes for each. If the URLPattern name
matches an Informative Text, attach that
Informative Text to the route.
"""
informative_texts = InformativeText.objects.all()

for pattern in CURRENT_URLPATTERNS[0]:
gathered_text = informative_texts.filter(name=f'{str(pattern.name).title()} Information')
if gathered_text is not None:
current_routes.append(
Route(
name=pattern.name,
route_type="main_with_text",
informative_text=gathered_text.first()
)
)
else:
current_routes.append(
Route(
name=pattern.name,
route_type="main"
)
)

site_info: SiteInformation.objects = SiteInformation.objects.get_or_create(pk=1)[0]

current_routes: list = []

try:
site_avatar_url = f"{WEB_PROTO}://{DOMAIN_NAME}/{site_info.avatar_image.url}"
site_avatar_url = f"{WEB_PROTO}://{DOMAIN_NAME}{site_info.avatar_image.url}"
except ValueError:
site_avatar_url = f"{WEB_PROTO}://{DOMAIN_NAME}/static/image/no_user.webp"


# If request is to root path, we do not need to check routes
if request.path == '/':
return {
"og_color": site_info.main_color,
"og_url": f"{WEB_PROTO}://{DOMAIN_NAME}",
"og_image": f"{WEB_PROTO}://{DOMAIN_NAME}/{site_avatar_url}",
"og_image": f"{site_avatar_url}",
"og_title": f"{site_info.brand_name} | Home",
"og_desc": site_info.meta_description
}

current_routes: list = []

for pattern in CURRENT_URLPATTERNS[0]:
current_routes.append(
Route(
name=pattern.name,
route_type="main"
)
)

_get_main_routes()
_get_user_routes()
_get_page_routes()

Expand All @@ -107,15 +130,15 @@ def _get_page_routes():

if route.user != None:
try:
user_avatar = route.user.user_profile_info.profile_picture.url
user_avatar = f"{WEB_PROTO}://{DOMAIN_NAME}{route.user.user_profile_info.profile_picture.url}"
except ValueError:
user_avatar = site_avatar_url

return {
"og_user": route.user,
"og_color": site_info.main_color,
"og_url": f"{WEB_PROTO}://{DOMAIN_NAME}/{BASE_USER_URL}/{route.user.user_slug}",
"og_image": f"{WEB_PROTO}://{DOMAIN_NAME}/{user_avatar}",
"og_image": f"{user_avatar}",
"og_title": f"{site_info.brand_name} | {route.user.username}",
"og_desc": f"User Profile for {route.user.username}"
}
Expand All @@ -125,27 +148,27 @@ def _get_page_routes():
"og_page": route.page,
"og_color": site_info.main_color,
"og_url": f"{WEB_PROTO}://{DOMAIN_NAME}/{route.page.get_absolute_url()}",
"og_image": f"{WEB_PROTO}://{DOMAIN_NAME}/{site_avatar_url}",
"og_image": f"{site_avatar_url}",
"og_title": f"{site_info.brand_name} | {route.page.name}",
"og_desc": route.page.meta_description
}

try:
text_content = strip_tags(
InformativeText.objects.get(
name=f"{path.title()} Information"
).content
)
except InformativeText.DoesNotExist:
LOGGER.error(f"Informative Text not found for following path: {path}")
text_content = "Placeholder"
if route.informative_text != None:
return {
"og_color": site_info.main_color,
"og_url": f"{WEB_PROTO}://{DOMAIN_NAME}/{path}",
"og_image": f"{site_avatar_url}",
"og_title": f"{site_info.brand_name} | {path.title()}",
"og_desc": strip_tags(route.informative_text.content)
}

return {
"og_color": site_info.main_color,
"og_url": f"{WEB_PROTO}://{DOMAIN_NAME}/{path}",
"og_image": f"{WEB_PROTO}://{DOMAIN_NAME}/{site_avatar_url}",
"og_image": f"{site_avatar_url}",
"og_title": f"{site_info.brand_name} | {path.title()}",
"og_desc": text_content
"og_desc": site_info.meta_description
}


return False
32 changes: 13 additions & 19 deletions raptorWeb/templates/raptormc/defaultpages/joining.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,33 @@ <h3 class="pageHeader fw-bold text-center mb-2">Joining {{ site_info_model.brand

</section>

<section id="joinBoxes" class="row mt-3">
<section id="joinBoxes" class="container row mt-3">

{% if Using_the_CurseForge_Launcher.enabled %}
<div class="col-12">
<div class="card bg-light mt-4 opacity-75 container">
<h3 class="pageHeader card-header fw-bold text-center text-break">CurseForge Launcher</h3>
<div class="pageContent p-4">
{{ Using_the_CurseForge_Launcher.content|safe }}
</div>
<div class="card bg-light mt-4 opacity-75">
<h3 class="pageHeader card-header fw-bold text-center text-break">CurseForge Launcher</h3>
<div class="pageContent p-4">
{{ Using_the_CurseForge_Launcher.content|safe }}
</div>
</div>
{% else %}
{% endif %}

{% if Using_the_FTB_Launcher.enabled %}
<div class="col-12">
<div class="card bg-light mt-4 opacity-75 container">
<h3 class="pageHeader card-header fw-bold text-center text-break">Feed the Beast App</h3>
<div class="pageContent p-4">
{{ Using_the_FTB_Launcher.content|safe }}
</div>
<div class="card bg-light mt-4 opacity-75">
<h3 class="pageHeader card-header fw-bold text-center text-break">Feed the Beast App</h3>
<div class="pageContent p-4">
{{ Using_the_FTB_Launcher.content|safe }}
</div>
</div>
{% else %}
{% endif %}

{% if Using_the_Technic_Launcher.enabled %}
<div class="col-12">
<div class="card bg-light mt-4 opacity-75 container">
<h3 class="pageHeader card-header fw-bold text-center text-break">Technic Launcher</h3>
<div class="pageContent p-4">
{{ Using_the_Technic_Launcher.content|safe }}
</div>
<div class="card bg-light mt-4 opacity-75">
<h3 class="pageHeader card-header fw-bold text-center text-break">Technic Launcher</h3>
<div class="pageContent p-4">
{{ Using_the_Technic_Launcher.content|safe }}
</div>
</div>
{% else %}
Expand Down

0 comments on commit fb0c585

Please sign in to comment.