Skip to content

Commit

Permalink
feat: fix numerous bugs; v1.1.0 (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
MagneticNeedle authored Oct 6, 2022
2 parents b1ba19f + adf6c70 commit 30252a6
Show file tree
Hide file tree
Showing 20 changed files with 756 additions and 200 deletions.
25 changes: 14 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ name: Docker Build

on:
workflow_dispatch:
# Run tests for any PRs.
pull_request:
branches:
- none

push:
branches:
- main
Expand Down Expand Up @@ -44,13 +47,13 @@ jobs:
docker tag $BRANCH_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
# update-portainer:
# needs: production-deploy
# runs-on: ubuntu-latest
# steps:
# - name: post to webhook
# uses: fjogeleit/http-request-action@v1
# with:
# url: ${{ secrets.PORTAINER_WEBHOOK_URL }}
# method: 'POST'
# timeout: 180000
update-portainer:
needs: production-deploy
runs-on: ubuntu-latest
steps:
- name: post to webhook
uses: fjogeleit/http-request-action@v1
with:
url: ${{ secrets.PORTAINER_WEBHOOK_URL }}
method: 'POST'
timeout: 180000
1 change: 1 addition & 0 deletions bfportal/bfportal/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@

# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
EMAIL_BACKEND = "django.core.mail.backends.dummy.EmailBackend"
WAGTAILADMIN_BASE_URL = "http://example.com"
LOGIN_REDIRECT_URL = "/"
LOGIN_URL = "/discord/login/"
Expand Down
Binary file added bfportal/bfportal/static/images/default_meta.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bfportal/bfportal/static/images/placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
197 changes: 117 additions & 80 deletions bfportal/bfportal/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,58 +1,52 @@
{% load static wagtailcore_tags wagtailuserbar account socialaccount tailwind_tags %}
{% load template_filters %}
{% load static wagtailcore_tags wagtailimages_tags account socialaccount tailwind_tags %}
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8"/>
<title>
{% block title %}
{% if page.seo_title %}{{ page.seo_title }}{% else %}{{ page.title }}{% endif %}
{% endblock %}
{% block title_suffix %}
{% wagtail_site as current_site %}
{% if current_site and current_site.site_name %}- {{ current_site.site_name }}{% endif %}
{% endblock %}
</title>
<title>{% block title %}{% if page.meta_title %}{{ page.meta_title }}{% else %}{{ page.title }}
{% endif %}{% endblock %}</title>
<link rel="icon" type="image/x-icon" href={% static "images/fav.gif" %}>
<meta property="og:title" content="{{ page.title|title }}"/>
<meta property="og:type" content="website">

<meta name="twitter:card" content="summary_large_image">
<meta property="twitter:domain" content="vmi659995.contaboserver.net">
<meta property="twitter:url" content="{{ request.build_absolute_uri }}">
<meta name="twitter:title" content="{{ page.title|title }}">

{% if page.is_experience_page %}

<meta property="og:description" content="{{ page.description }}"/>
<meta name="description" content="{{ page.description }}"/>
<meta property="og:image" content="
{% if page.cover_img_url %}{{ page.cover_img_url }}{% else %}{{ request.scheme }}://{{ request.META.HTTP_HOST }}{% static 'images/placeholder.png' %}{% endif %}"/>

<!-- Twitter Meta Tags -->

<meta name="twitter:description" content="{{ page.description }}">
<meta name="twitter:image" content="
{% if page.cover_img_url %}{{ page.cover_img_url }}{% else %}{{ request.scheme }}://{{ request.META.HTTP_HOST }}{% static 'images/placeholder.png' %}{% endif %}">

{% else %}
<meta name="twitter:description"
content="{% if page.seo_title %}{{ page.seo_title }}{% else %}{{ page.title }}{% endif %}">
<meta name="twitter:image"
content="{{ request.scheme }}://{{ request.META.HTTP_HOST }}{% static 'images/bf_portal_logo_bc.png' %}">

<meta name="description"
content="{% if page.seo_title %}{{ page.seo_title }}{% else %}{{ page.title }}{% endif %}"/>
<meta property="og:description"
content="{% if page.seo_title %}{{ page.seo_title }}{% else %}{{ page.title }}{% endif %}"/>
<meta property="og:image"
content="{{ request.scheme }}://{{ request.META.HTTP_HOST }}{% static 'images/bf_portal_logo_bc.png' %}"/>
{% endif %}

{% if not disable_preview_embed %}
<meta property="og:title"
content="{% if page.meta_title %}{{ page.meta_title }}{% else %}{{ page.title }}{% endif %}"/>
<meta property="og:type" content="website">
<meta name="twitter:card" content="summary_large_image">
<meta property="twitter:domain" content="bfportal.gg">
<meta property="twitter:url" content="{{ request.build_absolute_uri }}">
<meta name="twitter:title"
content="{% if page.meta_title %}{{ page.meta_title }}{% else %}{{ page.title }}{% endif %}">
{% if page %}
{% if page.meta_description %}
{% with page.meta_description as description %}
<meta property="og:description" content="{{ description }}"/>
<meta name="description" content="{{ description }}"/>
<meta property="og:description" content="{{ description }}"/>
{% endwith %}
{% endif %}
{% if page.meta_image %}
{% with page.meta_image as image_url %}
<meta property="og:image" content="{{ image_url }}"/>
<meta name="twitter:image" content="{{ image_url }}">
{% endwith %}
{% else %}
{% if page.is_experience_page %}
{% with page.description as description %}
<meta property="og:description" content="{{ description }}"/>
<meta name="description" content="{{ description }}"/>
<meta property="og:description" content="{{ description }}"/>
{% endwith %}
<meta property="og:image" content="{{ page.cover_img_url }}"/>
<meta property="twitter:image" content="{{ page.cover_img_url }}"/>
{% endif %}{% endif %}{% else %}
<meta name="twitter:description" content="Battlefield Portal Library">
<meta name="twitter:image" content="{{ request|get_opg_image_url }}">
<meta name="description" content="Share & Find experiences made on portal.battlefield.com"/>
<meta property="og:description" content="Share & Find experiences made on portal.battlefield.com"/>
<meta property="og:image" content="{{ request|get_opg_image_url }}"/>
{% endif %}{% endif %}

<meta name="viewport" content="width=device-width, initial-scale=1"/>

{% block preload_media %}{% endblock %}
{% block extra_css %}
{# Override this in templates to add extra stylesheets #}
Expand All @@ -61,42 +55,42 @@
{% tailwind_css %}
<script type="text/javascript" src="{% static 'js/preload.js' %}"></script>
<script type="text/javascript">
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function toggleDropdown(id) {
const drpDown = document.getElementById(id)
drpDown.classList.toggle("invisible");
drpDown.style.opacity = '0%';
drpDown.style.top = '0rem';
anime({
targets: `#${id}`,
opacity: '100%',
top: '2rem',
easing: 'easeOutQuint',
duration: "200"
});
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function toggleDropdown(id) {
const drpDown = document.getElementById(id)
drpDown.classList.toggle("invisible");
drpDown.style.opacity = '0%';
drpDown.style.top = '0rem';
anime({
targets: `#${id}`,
opacity: '100%',
top: '2rem',
easing: 'easeOutQuint',
duration: "200"
});

}
}

function addDropDownPair(buttonID, menuID) {
const button = document.getElementById(buttonID),
menu = document.getElementById(menuID);
function addDropDownPair(buttonID, menuID) {
const button = document.getElementById(buttonID),
menu = document.getElementById(menuID);

if(button) {
button.addEventListener('click', function () {
toggleDropdown(menuID)
})
if (button) {
button.addEventListener('click', function () {
toggleDropdown(menuID)
})

menu.addEventListener('click', function (event) {
event.stopPropagation();
});
menu.addEventListener('click', function (event) {
event.stopPropagation();
});

// Close the dropdown if the user clicks outside it
window.addEventListener('click',function (event) {
if (!event.target.closest(`#${buttonID}`)) document.getElementById(menuID).classList.add('invisible');
})
// Close the dropdown if the user clicks outside it
window.addEventListener('click', function (event) {
if (!event.target.closest(`#${buttonID}`)) document.getElementById(menuID).classList.add('invisible');
})
}
}
}
</script>
</head>

Expand All @@ -115,6 +109,13 @@
})
</script>
{% endblock %}
{% if not no_cat_description and cat_description %}
<div class="text-white flex w-11/12 mx-auto">
<div class="text-white text-sm font-medium prose prose-invert min-w-fit mt-10">
{{ cat_description|show_markdown|safe }}
</div>
</div>
{% endif %}
{% block content %}{% endblock %}
</div>

Expand Down Expand Up @@ -177,7 +178,13 @@
const id = elem.getAttribute("like_count_container");
fetch(`/api/like/${id}/`).then(
function (resp) {
return resp.json()
console.log(resp.url)
if (resp.redirected) {
document.location = `${resp.url.split("=")[0]}=${document.location.pathname}`
} else {
return resp.json()
}

}
).then(function (data) {
const fav_containers = document.querySelectorAll(`[fav_count_container='${id}']`),
Expand All @@ -201,10 +208,40 @@
})
}

fetch('https://discord.com/api/guilds/870246147455877181/widget.json').then(
resp => {
resp.json().then(json => {
const totalCount = parseInt(json['presence_count']),
span = document.createElement('span');

span.className = "text-xs text-bg-light"
document.getElementById('discord-nav').appendChild(span)

if (document.location.pathname === '/') {
const duration = 5,
countStep = Math.trunc((totalCount / duration) / 50);

let currCount = 0

function increaseCount() {
span.innerHTML = `&nbsp;&nbsp;${currCount} members online`
if (totalCount >= currCount) {
currCount += countStep
setTimeout(increaseCount, duration)
}
}
increaseCount()
} else {
span.innerHTML = `&nbsp;&nbsp;${totalCount} members online`

}

})
}
)
</script>
{% block extra_js %}
{# Override this in templates to add extra javascript #}
{% endblock %}
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion bfportal/bfportal/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<a href="https://discord.gg/8un9qY5AvV"
target="_blank"
class="cursor-alias text-white font-bold hover:text-[#cccccc] transition duration-100 ease-in-out">
Discord
<p id="discord-nav">Discord</p>
</a>

{% block extend_navbar %}
Expand Down
1 change: 1 addition & 0 deletions bfportal/core/management/commands/import_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def handle(self, *args, **options): # noqa: D102
row.last_edited_time, "%B %d %Y %I %S %p"
).replace(tzinfo=timezone.utc)
page.tags.add(*row.tags)
page.first_publish = False
exps_page = ExperiencesPage.objects.first()
exps_page.add_child(instance=page)
exps_page.save()
Expand Down
35 changes: 35 additions & 0 deletions bfportal/core/management/commands/validate_experiences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from urllib.parse import parse_qs, urlsplit # noqa: E402

import requests # noqa: E402
from core.models import ExperiencePage # noqa: E402
from django.core.management import BaseCommand # noqa: E402


def request_response_handler(response, *args, **kwargs):
"""Async callback for response"""
print(response)


def exception_handler(*args):
"""Async callback for error handling"""
print(args)


class Command(BaseCommand):
"""A command to validate all share codes and playground URL"""

help = "validates all share codes and playground URL"

def handle(self, *args, **options): # noqa: D102
experiences = ExperiencePage.objects.live().public()
urls = []
experience: ExperiencePage
for experience in experiences:
base_url = "https://api.gametools.network/bf2042/playground/?{}&blockydata=false&lang=en-us"
if experience.exp_url:
parsed_url = urlsplit(experience.exp_url)
query_dict = parse_qs(parsed_url.query)
if playgroundId := query_dict.get("playgroundId", None):
urls.append(base_url.format(f"playgroundid={playgroundId[0]}"))
elif experience.code:
urls.append(base_url.format(f"experiencecode={experience.code}"))
30 changes: 30 additions & 0 deletions bfportal/core/migrations/0056_auto_20221003_1943.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 3.2.12 on 2022-10-03 19:43

import markdownx.models
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("core", "0055_auto_20221001_1417"),
]

operations = [
migrations.AddField(
model_name="experiencescategory",
name="description",
field=markdownx.models.MarkdownxField(
blank=True,
help_text="description of this category that is shown on /category/",
),
),
migrations.AddField(
model_name="subcategory",
name="description",
field=markdownx.models.MarkdownxField(
blank=True,
help_text="description of this category that is shown on /category/",
),
),
]
21 changes: 21 additions & 0 deletions bfportal/core/migrations/0057_profile_hide_username.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.12 on 2022-10-03 20:07

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0056_auto_20221003_1943"),
]

operations = [
migrations.AddField(
model_name="profile",
name="hide_username",
field=models.BooleanField(
default=False,
help_text="If set to true hides the username on the website",
),
),
]
Loading

0 comments on commit 30252a6

Please sign in to comment.