mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-21 16:55:25 +03:00
Fix spoiler content accidentally get leaked in document.title
- Also add quotes - Add comment to why use 64 chars (soft) limit
This commit is contained in:
parent
2ddc1b8005
commit
94dd2bf627
1 changed files with 12 additions and 5 deletions
|
@ -111,18 +111,25 @@ export default ({ id }) => {
|
|||
}, [heroStatus]);
|
||||
const heroContentText = useMemo(() => {
|
||||
if (!heroStatus) return '';
|
||||
const { content } = heroStatus;
|
||||
const div = document.createElement('div');
|
||||
div.innerHTML = content;
|
||||
let text = div.innerText.trim();
|
||||
const { spoilerText, content } = heroStatus;
|
||||
let text;
|
||||
if (spoilerText) {
|
||||
text = spoilerText;
|
||||
} else {
|
||||
const div = document.createElement('div');
|
||||
div.innerHTML = content;
|
||||
text = div.innerText.trim();
|
||||
}
|
||||
if (text.length > 64) {
|
||||
// "The title should ideally be less than 64 characters in length"
|
||||
// https://www.w3.org/Provider/Style/TITLE.html
|
||||
text = text.slice(0, 64) + '…';
|
||||
}
|
||||
return text;
|
||||
}, [heroStatus]);
|
||||
useTitle(
|
||||
heroDisplayName && heroContentText
|
||||
? `${heroDisplayName}: ${heroContentText}`
|
||||
? `${heroDisplayName}: "${heroContentText}"`
|
||||
: 'Status',
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue