Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nawinds/nawinds-site
Browse files Browse the repository at this point in the history
# Conflicts:
#	templates/index.jinja2
#	translations/en/LC_MESSAGES/messages.mo
#	translations/en/LC_MESSAGES/messages.po
#	translations/ru/LC_MESSAGES/messages.mo
  • Loading branch information
Nikita Aksenov committed Dec 11, 2023
2 parents 95b9acf + 761f4f7 commit 37ef0da
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 92 deletions.
18 changes: 9 additions & 9 deletions blueprints/multilingual.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def pull_lang_code(endpoint, values):

@multilingual.route('/')
def index():
show_new_domain_msg = request.args.get("new_domain", "0") == "1"

sail_images = os.listdir("static/sail/")

today = datetime.date.today()
Expand All @@ -45,17 +47,15 @@ def index():
with open("projects.json", "r", encoding="UTF-8") as fcc_file:
projects = json.load(fcc_file)

if (not request.cookies.get("lang", None) and g.lang_code !=
request.accept_languages.best_match(LANGUAGES)
) or (request.cookies.get("lang", None) and g.lang_code !=
request.cookies.get("lang") and g.lang_code !=
request.accept_languages.best_match(LANGUAGES)):
show_switch_lang_popup = True
else:
show_switch_lang_popup = False
show_switch_lang_popup = (not request.cookies.get("lang", None) and g.lang_code !=
request.accept_languages.best_match(LANGUAGES)
) or (request.cookies.get("lang", None) and g.lang_code !=
request.cookies.get("lang") and g.lang_code !=
request.accept_languages.best_match(LANGUAGES))

return render_template("index.jinja2",
sail_images=sail_images, age=age, year=today.year,
gitea=gitea, github=github, telegram=telegram,
instagram=instagram, vk=vk, email=email, tg_channel=tg_channel,
projects=projects, show_switch_lang_popup=show_switch_lang_popup)
projects=projects, show_switch_lang_popup=show_switch_lang_popup,
show_new_domain_msg=show_new_domain_msg)
25 changes: 19 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import requests
from flask import Flask, render_template, send_file, request, g, redirect, url_for
from flask_babel import Babel
from flask_babel import Babel, _

from blueprints.multilingual import multilingual, LANGUAGES

Expand All @@ -17,8 +17,8 @@


def get_locale():
if not g.get('lang_code', None):
if not request.cookies.get('lang', None):
if g.get('lang_code', None) not in LANGUAGES:
if request.cookies.get('lang', None) not in LANGUAGES:
if not request.accept_languages.best_match(LANGUAGES):
ip_country = request.headers.get("CF-IPCountry")
g.lang_code = "ru" if ip_country == "RU" else "en"
Expand All @@ -35,6 +35,19 @@ def get_locale():
@app.route('/')
def index():
g.lang_code = get_locale()
if request.args.get("new_domain") == "1":
return redirect(url_for('multilingual.index', new_domain="1"))
return redirect(url_for('multilingual.index'))


# NEW DOMAIN MESSAGE FORM HANDLER
@app.route("/new_domain", methods=["POST"])
def new_domain_form():
message = request.form.get("msg", None)
if message:
requests.get(f"https://api.telegram.org/bot{TG_BOT_TOKEN}/sendMessage?"
f"chat_id={TG_CHAT_ID}&text=Nawinds:%20OLD_DOMAIN_FEEDBACK:%20{message}")
g.lang_code = get_locale()
return redirect(url_for('multilingual.index'))


Expand Down Expand Up @@ -81,9 +94,9 @@ def killer():

@app.errorhandler(404)
def not_found(e):
return render_template("error.jinja2", status_code="404", error_heading="Страница не найдена",
error_description="Этой страницы не существует. "
"Вы можете перейти на <a href=\"/\">главную</a>."), 404
return render_template("error.jinja2", status_code="404",
error_heading=_("not_found_header"),
error_description=_("not_found_desc")), 404


if __name__ == '__main__':
Expand Down
115 changes: 115 additions & 0 deletions static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,118 @@ footer .copyright {
}
}

/* NEW DOMAIN MESSAGE */

#new-domain-background {
background-color: rgba(0, 0, 0, 0.8);
width: 100vw;
height: 100vh;
z-index: 900;
position: fixed;
}

#new-domain {
position: absolute;
left: 50vw;
top: 50vh;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
display: inline-block;
text-align: center;
background: black;
padding: 25px 30px 10px 30px;
max-width: 50em;
width: 70vw;
z-index: 999;
border-radius: 15px;
font-family: "Arial", sans-serif;
height: max-content;
}

#new-domain form {
max-width: 40em;
width: 80%;
display: inline-block;
font-family: "Comfortaa", sans-serif;
text-align: center;
}

#new-domain form textarea {
background-color: white;
border: none;
border-radius: 7px;
width: 100%;
padding: 0;
}

#new-domain form input[type=submit] {
margin-top: 5px;
border: solid 1px white;
color: white;
border-radius: 7px;
background-color: transparent;
padding: 7px;
display: block;
margin-left: auto;
width: 100%;
cursor: pointer;
transition: ease-in-out 0.2s;
}

#new-domain form input[type=submit]:hover {
background-color: white;
color: black;
}

#new-domain form textarea {
font: 1em / 1.5 sans-serif;
padding: 7px;
width: calc(100% - 14px);
}

#new-domain div {
display: block;
margin-top: 20px;
}

#new-domain div button {
background-color: yellow;
padding: 10px;
font-size: 18px;
color: black;
border-radius: 15px;
border: 1px solid yellow;
display: inline;
cursor: pointer;
transition: ease-in-out 0.2s;
}

#new-domain div button:hover {
background-color: black;
color: yellow;
border: 1px solid yellow;
}

#new-domain h1 {
padding: 6px;
display: block;
}

.red {
text-decoration: line-through;
color: red;
}

.gr {
background-color: yellow;
color: black;
padding: 3px;
border-radius: 5px;
}

.new-domain-lang {
color: #b1b1b1;
position: absolute;
right: 10px;
margin-bottom: 10px;
}
15 changes: 15 additions & 0 deletions static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,19 @@ window.onload = function () {
el.style = "";
}
});
}

// NEW DOMAIN

function hideNewDomain() {
const background = document.getElementById("new-domain-background");
const banner = document.getElementById("new-domain");
background.style.display = "none";
banner.style.display = "none";

const url = window.location.href;
const urlObj = new URL(url);
urlObj.search = '';
const result = urlObj.toString();
history.pushState({}, null, result);
}
6 changes: 3 additions & 3 deletions static/robots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ Allow: /
Disallow: /lucky$
Disallow: /killer$
Disallow: /api/*
Sitemap: https://nawinds.top/sitemap.xml
Sitemap: https://nawinds.dev/sitemap.xml

User-agent: Yandex
Allow: /
Disallow: /lucky$
Disallow: /killer$
Disallow: /api/*
Sitemap: https://nawinds.top/sitemap.xml
Sitemap: https://nawinds.dev/sitemap.xml

User-agent: Googlebot
Allow: /
Disallow: /lucky$
Disallow: /killer$
Disallow: /api/*
Sitemap: https://nawinds.top/sitemap.xml
Sitemap: https://nawinds.dev/sitemap.xml
12 changes: 6 additions & 6 deletions static/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://nawinds.top/en/</loc>
<loc>https://nawinds.dev/en/</loc>
<xhtml:link
rel="alternate"
hreflang="ru"
href="https://nawinds.top/ru/"/>
href="https://nawinds.dev/ru/"/>
<xhtml:link
rel="alternate"
hreflang="en"
href="https://nawinds.top/en/"/>
href="https://nawinds.dev/en/"/>
</url>
<url>
<loc>https://nawinds.top/ru/</loc>
<loc>https://nawinds.dev/ru/</loc>
<xhtml:link
rel="alternate"
hreflang="ru"
href="https://nawinds.top/ru/"/>
href="https://nawinds.dev/ru/"/>
<xhtml:link
rel="alternate"
hreflang="en"
href="https://nawinds.top/en/"/>
href="https://nawinds.dev/en/"/>
</url>
</urlset>
25 changes: 23 additions & 2 deletions templates/index.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

<link rel="manifest" href="{{ url_for('static', filename='manifest.json') }}">

<link rel="alternate" hreflang="en" href="https://nawinds.top/en/">
<link rel="alternate" hreflang="ru" href="https://nawinds.top/ru/">
<link rel="alternate" hreflang="en" href="{{ url_for('multilingual.index', lang_code='en') }}">
<link rel="alternate" hreflang="ru" href="{{ url_for('multilingual.index', lang_code='ru') }}">

<title>{{ _('page_title') }}</title>

Expand Down Expand Up @@ -69,6 +69,27 @@
<a id="scroll-up" onclick="scrollUp()">
<img src="{{ url_for('static', filename='icons/angle-up.svg') }}" alt="{{ _('up') }}">
</a>

{% if show_new_domain_msg %}
<!-- NEW DOMAIN MESSAGE -->
<div id="new-domain-background">
<div id="new-domain">
<a class="new-domain-lang" href="{{ url_for('multilingual.index',
lang_code=_('language_switch_link')) }}?new_domain=1#force_lang">{{ _('new_domain_lang') }}</a>
<h1><span class="red">nawinds.top</span> &#8594; <span class="gr">nawinds.dev</span></h1>
<h3>{{ _('new_domain_header') }}</h3>
<p>{{ _('new_domain_text') }}</p>
<form method="post" action="/new_domain">
<textarea name="msg" rows="4" placeholder="{{ _('new_domain_form_placeholder') }}"></textarea>
<input type="submit" value="{{ _('new_domain_form_button') }}">
</form>
<div>
<button onclick="hideNewDomain()">{{ _('new_domain_close_button') }}</button>
</div>
</div></div>
<!-- END NEW DOMAIN MESSAGE -->
{% endif %}

<div id="language-switch">
<a id="language-switch-button" href="{{ url_for('multilingual.index',
lang_code=_('language_switch_link')) }}#force_lang">
Expand Down
Binary file modified translations/en/LC_MESSAGES/messages.mo
Binary file not shown.
Loading

0 comments on commit 37ef0da

Please sign in to comment.