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

fixes & improvements #11

Merged
merged 1 commit into from
Mar 11, 2020
Merged

fixes & improvements #11

merged 1 commit into from
Mar 11, 2020

Conversation

ideas-into-software
Copy link
Contributor

Hi,

I just committed few fixes and improvements which I needed to make. Those are:

  1. FIX: file not being closed
    In lib/jekyll-linkpreview.rb, function save_cache_file had a problem due to file not being closed. This error could be seen on first generation / when no cache entry existed for given URL and attempt to create then read cache entry for given URL was made.

  2. FIX: variable not being extracted properly
    This error prevented me from passing URLs as variables to the linkpreview tag. Now either string or a variable can be passed with no problems.

  3. IMPROVEMENT: ability to customize layout via template - instead of using those embedded in plugin source code
    More information about this in code and the updated README.md file.

  4. Other:

  • updated 'spec/jekyll-linkpreview_spec.rb'
  • bumped 'lib/jekyll-linkpreview/version.rb' to version 0.3.0
  • bumped 'jekyll-linkpreview.gemspec' jekyll version to '3.8.6'
  • updated 'README.md'

Some of these fixes and improvements actually coinicide with issues I noticed you had open, which you can now close, i.e.:

Regards,
Michael

@ysk24ok
Copy link
Owner

ysk24ok commented Dec 9, 2019

FIX: variable not being extracted properly
This error prevented me from passing URLs as variables to the linkpreview tag.

Would you please add that case to tests ? Because it seems existing test cases passing a variable work properly.

@ideas-into-software
Copy link
Contributor Author

Hi,

I did update test case you've had ('spec/jekyll-linkpreview_spec.rb') to reflect changes I made.

Unfortunately, I do not have time to create new test cases now - however, if you wish to verify, it's enough to create new Jekyll site (e.g. jekyll new jekyll-linkpreview-testsite), add the plugin (currently released version, i.e. 0.2.0), then attempt to use variables instead of strings, and you'll see how this works, i.e. it does not. Also, you have an existing open issue #2 which talks about the same thing, i.e. not being able to use variables in Jekyll sites when using current version of your plugin.

So, to summarize, having this work in an actual deployment (i.e. Jekyll site) is more important than automated test cases which obviously are missing something because the two are not in sync.

Hope this helps.

Michael

@ysk24ok
Copy link
Owner

ysk24ok commented Dec 13, 2019

It seems jekyll-linkpreview v0.2.0 does work with variables.
I tried creating new site by jekyll new, installing v0.2.0 and adding following code to index.md,

{% assign url = 'https://github.com' %}
{% linkpreview url %}

and confirmed it works fine like this.

スクリーンショット 2019-12-13 23 27 19

(the image is so big because no css is applied ...)

I want to know why your attempt to use variables fails. That's why I want you to add a testcase, which fails with v0.2.0 and passes with this pull request.
Could you explain your attempt more precisely?

Copy link
Owner

@ysk24ok ysk24ok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, thank you for this pull request! Custom template for preview is a cool feature.
But there is a bug when no custom template exists. Indentation in heredoc should be deleted, otherwise rendered HTML will be like this.

スクリーンショット 2019-12-20 20 41 28

1. Place `linkpreview_nog.html` file inside `_includes/` folder of your Jekyll site (`_includes/linkpreview_nog.html`)

2. Use built-in **link_url** variable to render URL data, i.e. `{{ link_url }}`

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the detailed explanation!

@@ -122,7 +96,7 @@ def get_properties(url)

private
def get_url_from(context)
context.scopes[0].key?(@markup) ? context.scopes[0][@markup] : @markup
context[@markup]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Becomes much simpler!
Now users have to pass quoted url like {% linkpreview 'https://github.com' %}, but it may be acceptable.

@@ -132,7 +106,69 @@ def load_cache_file(filepath)

protected
def save_cache_file(filepath, properties)
File.open(filepath, 'w').write(JSON.generate(properties))
File.open(filepath, 'w') { |f| f.write JSON.generate(properties) }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

<a href="//#{domain}" target="_blank">#{domain}</a>
</div>
</div>
</div>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation should be deleted because it doesn't rendered properly.

html = <<-EOS
<div class="jekyll-linkpreview-wrapper">
<p><a href="#{url}" target="_blank">#{url}</a></p>
</div>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation should be deleted, same reason above.

@ysk24ok
Copy link
Owner

ysk24ok commented Mar 11, 2020

There is a problem (heredoc indent) in this PR, but I'll fix it after merge.
Anyway, thank you for this PR!

@ideas-into-software
Copy link
Contributor Author

Hi, Sorry I could not help with formatting, I did not have the time to check GitHub since then. Thank you for the merge - glad I could help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants