Code Monkey home page Code Monkey logo

jekyll-linkpreview's People

Contributors

clpsplug avatar greatgumz avatar ideas-into-software avatar mostafa avatar ysk24ok avatar zerobase avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jekyll-linkpreview's Issues

Pass variable - e.g. front-matter into tag

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?

It can't be used.

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.

Access other og: properties

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?

Non-HTML spec compliant pages cause plugin to miss crucial elements

Original report: #37 (comment)

The issue

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.

The fix

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.

class NonOpenGraphPropertiesFactory
def from_page(page)
NonOpenGraphProperties.new(
page.title, page.url, get_description(page), page.host)
end

CI is failing

I noticed this while fixing #38 via #39.

The issue

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

Potential fix

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.

Pages with meta tags, all of whose property attr are unrelated to OG properties ruins the preview

The issue

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.

Expected behavior

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.

Actual behavior

This happened.

Image from Gyazo

  • Jekyll-linkpreview attempted to render the "link preview with OGP image snippet" (linkpreview.html) even though there are no OG properties on this page
  • The title, description, and image are missing (missing image is expected, but the other two are not.)

I 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)

Suspected issues

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.

private
def create_properties_from_page(page)
if page.meta_tags['property'].empty? then
factory = NonOpenGraphPropertiesFactory.new
else
factory = OpenGraphPropertiesFactory.new
end
factory.from_page(page)
end

(Any <meta> tag whose property attribute value matches og:.* on this page and the plugin would have avoided this issue.)

Potential fix

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.

Removing line 245 in jekyll-linkpreview.rb

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?

Fails fetching https://www.diamond.co.jp

  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>'

Take "source" config into consideration

The issue

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.

Potential fix

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.

def render(context)
url = get_url_from(context)
properties = get_properties(url)
render_linkpreview properties
end

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! ๐Ÿ˜„

Use user-defined template

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.

Show an appropriate error message when _cache directory does not exist

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.