ysk24ok / jekyll-linkpreview Goto Github PK
View Code? Open in Web Editor NEWJekyll plugin to generate link preview
Home Page: https://rubygems.org/gems/jekyll-linkpreview
License: MIT License
Jekyll plugin to generate link preview
Home Page: https://rubygems.org/gems/jekyll-linkpreview
License: MIT License
I'm looking for a way of passing a variable into the tag, such as front matter. This will allow the tag to be used in templates, rather than having to be added manually.
Ideally it would look something like {% linkpreview linkvariable %}
I've tried a couple of approaches, including firstly putting the front-matter variable directly into the tag, and secondly assigning the front matter to a different variable and putting that in the tag. Both times the variable text is output as a string rather than a variable.
Is there any way to do this?
Hi,
I used the tag within the markdown.
However, the tag content is displayed as it is and does not support preview.
Aren't we supposed to use tags within the markdown?
I want a detailed way to use it.
Thank you.
This is an awesome plugin!
I was wondering if it's possible to access other properties, like og:type
or og:site_name
for example.
Ultimately, the plugin could make available all the meta tags starting with og:
, or would that be too difficult?
Original report: #37 (comment)
A webpage can write something like this:
<html>
<head>
<link rel="stylesheet" href="something.css">
</head>
<body>
<title>Title here</title> <!-- Wait, that's illegal -->
</body>
</html>
This HTML has a <title>
tag within the <body>
tag, which is illegal.
This causes MetaInspector, one of this plugin's dependencies, to miss this element completely when attempting to access the .title
accessor; it only looks at the <title>
tag in the <meta>
tag.
An example of such pages is https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.InputSystem.InputSystem.html.
MetaInspector provides an alternative: the .best_title
accessor, which also looks at the title
tag within the body
tag. We can modify this part below to produce the best result possible.
jekyll-linkpreview/lib/jekyll-linkpreview.rb
Lines 117 to 121 in 61c8b0b
CI checks don't appear in a pull request page.
For example, #18 is build by Travis CI at https://travis-ci.org/github/ysk24ok/jekyll-linkpreview/builds/668236405 but it's not shown in #18 page.
I noticed this while fixing #38 via #39.
The CI is failing every time I push to GitHub.
It seems jekyll-sass-converter
received a major update and its dependency sass-embedded-1.57.1
has stopped supporting rubygems below 3.3.22, which is the default for the Docker image used for CI.
https://jekyllrb.com/news/2022/12/21/jekyll-sass-converter-3.0-released/
https://github.com/jekyll/jekyll-sass-converter/blob/master/jekyll-sass-converter.gemspec#L19
https://github.com/ntkme/sass-embedded-host-ruby/blob/5d751c76c57c5dd03620d48121c435863321d0b8/sass-embedded.gemspec#L25
An update of rubygems seems to do the trick.
Since the CI crashes on me every time I push to my fork as I try to fix the other issues (and GitHub is spamming me with the 'failure' emails), I'm working on a fix and am about to submit a PR.
I'm not sure if it is possible, though, since editing GitHub Actions usually requires a unique permission scope. If I am blocked b/c of security reasons, I'm afraid I have to ask you to do this. I can provide the patch.
I attempted to linkpreview
the following URL:
https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.InputSystem.InputSystem.html
It is a documentation page for Unity's package.
This link does not appear to have any OGP properties, so I expected this plugin to produce a "no OGP image link preview snippet" with the title Class InputSystem | Input System | 1.0.2
.
This happened.
linkpreview.html
) even though there are no OG properties on this pageI looked into the cache and found that the corresponding file had this:
{"title":null,"url":null,"image":null,"description":null,"domain":"docs.unity3d.com"}
(filename: cec2702fa0dbc6125ac754817ddbb10b.json)
This page has these <meta>
tags in its HTML:
<meta property="docfx:navrel" content="../toc.html">
<meta property="docfx:tocrel" content="toc.html">
<meta property="unity:packageTitle" content="Input System | 1.0.2">
<meta property="docfx:rel" content="../">
So this page has <meta>
tags with a property
attribute, but its value is never og:.*
. This edge case of an HTML page causes this method to miss this case and causes it to spawn OpenGraphPropertiesFactory
when it should be spawning NonOpenGraphPropertiesFactory
instead.
jekyll-linkpreview/lib/jekyll-linkpreview.rb
Lines 190 to 198 in 61c8b0b
(Any <meta>
tag whose property attribute value matches og:.*
on this page and the plugin would have avoided this issue.)
In addition to page.meta_tags['property'].empty?
, check for the total absence of property
attributes whose value matches regex og:.*
. If any of those holds, we should use NonOpenGraphPropertiesFactory
.
For example, og:image
tag of docs.docker.com is as follows,
<meta property="og:image" itemprop="image primaryImageOfPage" content="/images/[email protected]">
The content is a relative url, and a generated preview also becomes a relative one, but it's your site's relative url, not docs.docker.com.
The url should be converted to full url when generating a preview.
First of all great job on the plugin this is exactly what I needed and super simple. Only thing I need is to not have the URL show up on top of the preview.
When I build my website locally I just remove line 245 from jekyll-linkpreview.rb but when building though github-actions I cannot modify the ruby files since they are fetched from the source here.
Do you know how I could fix this without manually modifying my html after the website is deployed?
Liquid Exception: undefined method `[]' for nil:NilClass in /blog/_posts/2019-12-14-retrospect_2019.md
/var/lib/gems/2.3.0/gems/jekyll-linkpreview-0.2.0/lib/jekyll-linkpreview.rb:54:in `extract_domain': undefined method `[]' for nil:NilClass (NoMethodError)
from /var/lib/gems/2.3.0/gems/jekyll-linkpreview-0.2.0/lib/jekyll-linkpreview.rb:13:in `get'
from /var/lib/gems/2.3.0/gems/jekyll-linkpreview-0.2.0/lib/jekyll-linkpreview.rb:113:in `get_properties'
from /var/lib/gems/2.3.0/gems/jekyll-linkpreview-0.2.0/lib/jekyll-linkpreview.rb:69:in `render'
from /var/lib/gems/2.3.0/gems/liquid-4.0.0/lib/liquid/block_body.rb:109:in `render_node'
from /var/lib/gems/2.3.0/gems/liquid-4.0.0/lib/liquid/block_body.rb:88:in `block in render'
from /var/lib/gems/2.3.0/gems/liquid-4.0.0/lib/liquid/block_body.rb:75:in `each'
from /var/lib/gems/2.3.0/gems/liquid-4.0.0/lib/liquid/block_body.rb:75:in `render'
from /var/lib/gems/2.3.0/gems/liquid-4.0.0/lib/liquid/template.rb:208:in `block in render'
from /var/lib/gems/2.3.0/gems/liquid-4.0.0/lib/liquid/template.rb:242:in `with_profiling'
from /var/lib/gems/2.3.0/gems/liquid-4.0.0/lib/liquid/template.rb:207:in `render'
from /var/lib/gems/2.3.0/gems/liquid-4.0.0/lib/liquid/template.rb:220:in `render!'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:30:in `block (2 levels) in render!'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:42:in `measure_bytes'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:29:in `block in render!'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:49:in `measure_time'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/liquid_renderer/file.rb:28:in `render!'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/renderer.rb:126:in `render_liquid'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/renderer.rb:79:in `render_document'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/renderer.rb:62:in `run'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:479:in `render_regenerated'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:464:in `block (2 levels) in render_docs'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:463:in `each'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:463:in `block in render_docs'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:462:in `each_value'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:462:in `render_docs'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:191:in `render'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/site.rb:71:in `process'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/command.rb:28:in `process_site'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/commands/build.rb:65:in `build'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/commands/build.rb:36:in `process'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/commands/serve.rb:93:in `block in start'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/commands/serve.rb:93:in `each'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/commands/serve.rb:93:in `start'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/lib/jekyll/commands/serve.rb:75:in `block (2 levels) in init_with_program'
from /var/lib/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
from /var/lib/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
from /var/lib/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
from /var/lib/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
from /var/lib/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
from /var/lib/gems/2.3.0/gems/jekyll-3.8.5/exe/jekyll:15:in `<top (required)>'
from /usr/local/bin/jekyll:22:in `load'
from /usr/local/bin/jekyll:22:in `<main>'
link to #{domain} in the default template is broken.
jekyll-linkpreview/lib/jekyll-linkpreview.rb
Lines 256 to 258 in 94597ec
b6529d0 fixed a bug in link to #{domain}. and d3d8d36 removed "//" without reason.
Directories that this plugin would use are all expected to be present in the project root.
However, Jekyll has a configuration to change the 'content root' of the site. It can change where Jekyll looks for the contents to build a site.
# This config value makes `$PROJECT_ROOT/_content` the 'content root.' Anything outside of it isn't included on the site.
# This is useful if you have so many files you don't want to include in the build that your `exclude` list is ridiculously long.
source: "_content"
My site makes use of this configuration value. However, because the plugin only looks at the project root, I have to create a weird directory structure like this:
$PROJECT_ROOT
|-_content
| |-_posts
| |-_includes
| |-head.liquid
|-_cache
|-_includes
|-linkpreview.html
|-linkpreview_nog.html
Notice that I have to repeat _includes
dir twice.
Since the outer _includes
is outside of the 'content root,' Jekyll cannot auto-rebuild the site on a change to linkpreview.html
when running the command jekyll serve.
In Jekyll, it is possible to pull the configuration value from within the Tag class. This is done in a context-aware manner; for example, if you use the --config
option in the jekyll
command, it will use the value in a specified file instead of _config.yml.
class MyTag < Jekyll::Tag
def render(context)
# prints the config value! We *must* use the `config` variable available here, though.
p context.registers[:site].config['source']
"Output for this tag"
end
end
I gave a quick read of the source code, and it looks that capturing this value in the method below and prepending it to @@template_dir
should do the trick.
jekyll-linkpreview/lib/jekyll-linkpreview.rb
Lines 147 to 151 in 181981c
I'm not sure about the @@cache_dir
, though. The required change is precisely the same, but the _cache
dir looks fine to stay outside the content root for me. But again, that directory being aware of the "source" config also makes total sense.
I'd be happy to hear your opinion on this matter. Thanks for a great plugin! ๐
Starting in Ruby 3.2.0 the exists?
(pluralized) alias for exist?
has been removed.
It is required to use the singular-form exist?
As of v0.1.0, HTML to be rendered is hard-coded into Ruby code ( Linkpreview#render
).
It would be great if users can use their own templates for preview.
As of v0.1.0, running jekyll build
shows an error message such as Liquid Exception: No such file or directory @ rb_sysopen - _cache/e2010699be801aa8e113c30874b2bf2a.json
when _cache
directory does not exist. It is not helpful.
Showing _cache directory does not exist. Create it before you run 'jekyll build'
will be good.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.