Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mercury parser #817

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions article_forge/.vscode/settings.json

This file was deleted.

6 changes: 5 additions & 1 deletion article_forge/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

js_context = nil

article_cache = {}

configure do
Sinatra::Application.reset!
StyleMinifier.minify
Expand All @@ -25,7 +27,9 @@
font_family = FontPicker.pick(params["font_family"])

article_url = params["article_url"]
article_content = JSON.parse(`cd ../../mercury-parser && npx mercury-parser #{article_url}`)
article_content = article_cache[article_url] || JSON.parse(`cd ../../mercury-parser && npx mercury-parser #{article_url}`)

article_cache[article_url] = article_content

liquid :template, locals: {
title: article_content["title"],
Expand Down
5 changes: 4 additions & 1 deletion article_forge/style/stylesheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,11 @@ ul:has(img) {
}

.article__title {
margin: 0;
padding-bottom: 0.5rem;
h1 {

&:empty {
padding: 0;
margin: 0;
}
}
Expand Down
4 changes: 1 addition & 3 deletions article_forge/views/template.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
<body>
<article>
<a class="article__header" href="{{external_link}}">
<div class="article__title">
<h1>{{title}}</h1>
</div>
<h1 class="article__title">{{title}}</h1>
<div>{{byline}}</div>
<div>{{feed_name}}</div>
</a>
Expand Down
2 changes: 1 addition & 1 deletion capy/src/main/assets/mercury-parser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion capy/src/main/assets/stylesheet.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 1 addition & 13 deletions capy/src/main/java/com/jocmp/capy/articles/ArticleRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ArticleRenderer(

val substitutions = colors + mapOf(
"external_link" to article.externalLink(),
"title" to title(article.title),
"title" to article.title,
"byline" to byline,
"feed_name" to article.feedName,
"font_size" to "${textSize.get()}px",
Expand Down Expand Up @@ -71,18 +71,6 @@ class ArticleRenderer(
}
}

private fun title(articleTitle: String): String {
return if (articleTitle.isBlank()) {
""
} else {
"""
<div class="article__title">
<h1>${articleTitle}</h1>
</div>
""".trimIndent()
}
}

private fun fontPreload(fontFamily: FontOption): String {
return when (fontFamily) {
FontOption.SYSTEM_DEFAULT -> ""
Expand Down
2 changes: 1 addition & 1 deletion capy/src/main/res/raw/template.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.