Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jovuit
funkwhale
Commits
0ee0db7e
Unverified
Commit
0ee0db7e
authored
May 06, 2020
by
Agate
💬
Browse files
Fix
#1107
: Fix HTML <title> not including instance name in some situations
parent
90427331
Changes
4
Hide whitespace changes
Inline
Side-by-side
api/funkwhale_api/common/middleware.py
View file @
0ee0db7e
...
...
@@ -39,6 +39,9 @@ def serve_spa(request):
settings
.
FUNKWHALE_SPA_REWRITE_MANIFEST_URL
or
federation_utils
.
full_url
(
urls
.
reverse
(
"api:v1:instance:spa-manifest"
))
)
title
=
preferences
.
get
(
"instance__name"
)
if
title
:
head
=
replace_title
(
head
,
title
)
head
=
replace_manifest_url
(
head
,
new_url
)
if
not
preferences
.
get
(
"common__api_authentication_required"
):
...
...
@@ -82,6 +85,7 @@ def serve_spa(request):
MANIFEST_LINK_REGEX
=
re
.
compile
(
r
"<link [^>]*rel=(?:'|\")?manifest(?:'|\")?[^>]*>"
)
TITLE_REGEX
=
re
.
compile
(
r
"<title>.*</title>"
)
def
replace_manifest_url
(
head
,
new_url
):
...
...
@@ -90,6 +94,12 @@ def replace_manifest_url(head, new_url):
return
head
def
replace_title
(
head
,
new_title
):
replacement
=
"<title>{}</title>"
.
format
(
html
.
escape
(
new_title
))
head
=
TITLE_REGEX
.
sub
(
replacement
,
head
)
return
head
def
get_spa_html
(
spa_url
):
return
get_spa_file
(
spa_url
,
"index.html"
)
...
...
api/tests/common/test_middleware.py
View file @
0ee0db7e
import
html
import
time
import
pytest
from
django.http
import
HttpResponse
from
django.urls
import
reverse
...
...
@@ -55,10 +55,12 @@ def test_should_fallback(path, expected, mocker):
def
test_serve_spa_from_cache
(
mocker
,
settings
,
preferences
,
no_api_auth
):
preferences
[
"instance__name"
]
=
'Best Funkwhale "pod"'
request
=
mocker
.
Mock
(
path
=
"/"
)
get_spa_html
=
mocker
.
patch
.
object
(
middleware
,
"get_spa_html"
,
return_value
=
"<html><head></head></html>"
middleware
,
"get_spa_html"
,
return_value
=
"<html><head><title>Funkwhale</title></head></html>"
,
)
mocker
.
patch
.
object
(
middleware
,
...
...
@@ -84,7 +86,8 @@ def test_serve_spa_from_cache(mocker, settings, preferences, no_api_auth):
assert
response
.
status_code
==
200
expected
=
[
"<html><head>"
,
"<html><head>"
"<title>{}</title>"
.
format
(
html
.
escape
(
preferences
[
"instance__name"
])),
'<meta content="custom title" property="og:title" />'
,
'<meta content="custom description" property="og:description" />'
,
'<meta content="default site name" property="og:site_name" />'
,
...
...
changes/changelog.d/1107.enhancement
0 → 100644
View file @
0ee0db7e
Fix HTML <title> not including instance name in some situations (#1107)
front/src/App.vue
View file @
0ee0db7e
...
...
@@ -66,6 +66,7 @@ export default {
instanceUrl
:
null
,
showShortcutsModal
:
false
,
showSetInstanceModal
:
false
,
initialTitle
:
document
.
title
,
}
},
async
created
()
{
...
...
@@ -147,7 +148,6 @@ export default {
},
mounted
()
{
let
self
=
this
// slight hack to allow use to have internal links in
<
translate
>
tags
// while preserving router behaviour
document
.
documentElement
.
addEventListener
(
'
click
'
,
function
(
event
)
{
...
...
@@ -281,7 +281,7 @@ export default {
if
(
this
.
$store
.
state
.
ui
.
pageTitle
)
{
parts
.
push
(
this
.
$store
.
state
.
ui
.
pageTitle
)
}
parts
.
push
(
this
.
$store
.
state
.
instance
.
settings
.
instance
.
name
.
valu
e
||
'
Funkwhale
'
)
parts
.
push
(
this
.
initialTitl
e
||
'
Funkwhale
'
)
document
.
title
=
parts
.
join
(
'
–
'
)
},
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment