Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add reader mode view * Show link for latest snapshot instead
- Loading branch information
1 parent
0586983
commit 0cbaf92
Showing
11 changed files
with
2,551 additions
and
16 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
html.reader-mode { | ||
--font-size: 1rem; | ||
line-height: 1.6; | ||
|
||
body { | ||
margin: 3rem 2rem; | ||
} | ||
|
||
.container { | ||
max-width: 600px; | ||
} | ||
|
||
.byline { | ||
font-style: italic; | ||
font-size: 0.8rem; | ||
} | ||
|
||
.reading-time { | ||
font-size: 0.7rem; | ||
} | ||
|
||
img { | ||
max-width: 100%; | ||
height: auto; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ | |
@import "bookmark-form"; | ||
@import "settings"; | ||
@import "markdown"; | ||
@import "reader-mode"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{% load sass_tags %} | ||
{% load static %} | ||
<!DOCTYPE html> | ||
<html lang="en" class="reader-mode"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Reader view</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimal-ui"> | ||
{% if request.user_profile.theme == 'light' %} | ||
<link href="{% sass_src 'theme-light.scss' %}?v={{ app_version }}" rel="stylesheet" type="text/css"/> | ||
{% elif request.user_profile.theme == 'dark' %} | ||
<link href="{% sass_src 'theme-dark.scss' %}?v={{ app_version }}" rel="stylesheet" type="text/css"/> | ||
{% else %} | ||
{# Use auto theme as fallback #} | ||
<link href="{% sass_src 'theme-dark.scss' %}?v={{ app_version }}" rel="stylesheet" type="text/css" | ||
media="(prefers-color-scheme: dark)"/> | ||
<link href="{% sass_src 'theme-light.scss' %}?v={{ app_version }}" rel="stylesheet" type="text/css" | ||
media="(prefers-color-scheme: light)"/> | ||
{% endif %} | ||
</head> | ||
<body> | ||
<template id="content">{{ content|safe }}</template> | ||
<script src="{% static 'vendor/Readability.js' %}" type="application/javascript"></script> | ||
<script type="application/javascript"> | ||
function estimateReadingTime(charCount, wordsPerMinute) { | ||
const avgWordLength = 5; | ||
const totalWords = charCount / avgWordLength; | ||
return Math.ceil(totalWords / wordsPerMinute); | ||
} | ||
|
||
function postProcess(articleContent) { | ||
articleContent.querySelectorAll('table').forEach(table => { | ||
table.classList.add('table'); | ||
}); | ||
} | ||
|
||
function makeReadable() { | ||
const content = document.getElementById('content'); | ||
const contentHtml = content.innerHTML; | ||
const dom = new DOMParser().parseFromString(contentHtml, 'text/html'); | ||
const article = new Readability(dom).parse(); | ||
|
||
document.title = article.title; | ||
|
||
const container = document.createElement('div'); | ||
container.classList.add('container'); | ||
|
||
const articleTitle = document.createElement('h1'); | ||
articleTitle.textContent = article.title; | ||
container.append(articleTitle); | ||
|
||
const byline = [article.byline, article.siteName].filter(Boolean); | ||
if (byline.length > 0) { | ||
const articleByline = document.createElement('p'); | ||
articleByline.textContent = byline.join(' | '); | ||
articleByline.classList.add('byline'); | ||
container.append(articleByline); | ||
} | ||
|
||
if(article.length) { | ||
const minTime = estimateReadingTime(article.length, 225); | ||
const maxTime = estimateReadingTime(article.length, 175); | ||
|
||
const articleReadingTime = document.createElement('p'); | ||
articleReadingTime.textContent = `${minTime}-${maxTime} minutes`; | ||
articleReadingTime.classList.add('reading-time'); | ||
container.append(articleReadingTime); | ||
} | ||
|
||
const divider = document.createElement('hr'); | ||
container.append(divider); | ||
|
||
const articleContent = document.createElement('div'); | ||
articleContent.innerHTML = article.content; | ||
postProcess(articleContent); | ||
container.append(articleContent); | ||
|
||
content.replaceWith(container); | ||
} | ||
makeReadable(); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.