Skip to content

Commit

Permalink
feat: release v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gouravkhunger committed Jul 15, 2022
0 parents commit d1b8f96
Show file tree
Hide file tree
Showing 10 changed files with 351 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .gitignore
@@ -0,0 +1,58 @@
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/

# Used by dotenv library to load environment variables.
# .env

# Ignore Byebug command history file.
.byebug_history

## Specific to RubyMotion:
.dat*
.repl_history
build/
*.bridgesupport
build-iPhoneOS/
build-iPhoneSimulator/

## Specific to RubyMotion (use of CocoaPods):
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# vendor/Pods/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/

## Environment normalization:
/.bundle/
/vendor/bundle
/lib/bundler/man/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc

# Used by RuboCop. Remote config files pulled in from inherit_from directive.
# .rubocop-https?--*

.DS_Store
84 changes: 84 additions & 0 deletions CODE_OF_CONDUCT.md
@@ -0,0 +1,84 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.

Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at gouravkhunger18@gmail.com. All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series of actions.

**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.

Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source "https://rubygems.org"

# Specify your gem"s dependencies in jekyll-paginate-authors.gemspec
gemspec
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Gourav Khunger

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
70 changes: 70 additions & 0 deletions README.md
@@ -0,0 +1,70 @@
# Jekyll::URLMetadata

A jekyll plugin to extract meta information from urls and expose them to liquid variables.

This gem was originally authored to be used as a custom plugin for the [static site](https://github.com/genicsblog/genicsblog.com) of [genicsblog.com](https://genicsblog.com)

## Installation

Add this line to your application's Gemfile inside the `jekyll_plugins` group:

```ruby
group :jekyll_plugins do
# other gems
gem "jekyll-url-metadata"
end
```

Then, enable the plugin by adding it to the `plugins` section in the `_config.yml` file:

```yaml
plugins:
# - other plugins
- jekyll-url-metadata
```

And then execute:

```shell
bundle install
```

## Usage

This plugin is essentially a filter and works on any [valid URL string](https://en.wikipedia.org/wiki/URL#Syntax) provided inside a liquid tag. Use it as below:

```liquid
{% assign meta = "https://wikipedia.org" | metadata %}
```

The `metadata` filter extracts the meta data from the given url string.

These are the values that are extracted:

- The `<title>` tag.
- The `<meta>` tags that have a `name`, `property` or `charset` fields.
- The `<link>` tags with a `rel` attribute.

The expected output for `{{ meta }}` from the above example would be:

```
{
"title" => "Wikipedia",
"charset" => "utf-8",
"description" => "Wikipedia is a free online encyclopedia, created and edited by volunteers around the world and hosted by the Wikimedia Foundation.",
"viewport" => "initial-scale=1,user-scalable=yes",
"apple-touch-icon" => "/static/apple-touch/wikipedia.png",
"shortcut icon" => "/static/favicon/wikipedia.ico",
"license" => "//creativecommons.org/licenses/by-sa/3.0/",
"preconnect" => "//upload.wikimedia.org"
}
```

## Use cases

- Creating beautiful social previews for links by fetching meta data for URLs at build time.
- Determining meta data from a website at jekyll build time to evaluate and perform certain action.

## License

The gem is available as open source under the terms of the [MIT License](https://github.com/gouravkhunger/jekyll-url-metadata/blob/main/LICENSE).
3 changes: 3 additions & 0 deletions dev.sh
@@ -0,0 +1,3 @@
gem uninstall jekyll-url-metadata
gem build jekyll-url-metadata.gemspec
gem install --local jekyll-url-metadata-*.gem
28 changes: 28 additions & 0 deletions jekyll-url-metadata.gemspec
@@ -0,0 +1,28 @@
# coding: utf-8
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "jekyll-url-metadata/version"
require "date"

Gem::Specification.new do |spec|
spec.name = "jekyll-url-metadata"
spec.version = Jekyll::URLMetadata::VERSION
spec.platform = Gem::Platform::RUBY
spec.required_ruby_version = ">= 2.0.0" # Same as Jekyll
spec.date = DateTime.now.strftime("%Y-%m-%d")
spec.authors = ["Gourav Khunger"]
spec.email = ["gouravkhunger18@gmail.com"]
spec.homepage = "https://github.com/gouravkhunger/jekyll-url-metadata"
spec.license = "MIT"

spec.summary = "Extract all kind of meta data from a url string"
spec.description = "A plugin to expose meta data information from the head tag of a webapge to liquid variables just from its url string."

spec.files = Dir["*.gemspec", "Gemfile", "lib/**/*"]
spec.require_paths = ["lib"]

# Dependencies
spec.add_runtime_dependency "jekyll", ">= 3.0.0"
spec.add_runtime_dependency "nokogiri", ">= 1.10.0"

end
7 changes: 7 additions & 0 deletions lib/jekyll-url-metadata.rb
@@ -0,0 +1,7 @@
require "jekyll-url-metadata/version"
require "jekyll-url-metadata/main"

module Jekyll
module URLMetadata
end # module Jekyll
end # module URLMetadata
71 changes: 71 additions & 0 deletions lib/jekyll-url-metadata/main.rb
@@ -0,0 +1,71 @@
require "open-uri"
require "nokogiri"

module Jekyll
module URLMetadata

def metadata(input)
if !input.is_a?(String)
log("Expected input type \"String\". Got \"#{input.class}\".")
return
end

if input.nil? || input == ""
log("Empty input string.")
return
end

# parse HTML from URL
doc = Nokogiri::HTML(URI.open(input))
if !doc
log("Failed to parse HTML from #{input}. Please double check for URL validity.")
end

hash = Hash.new

# add <title> tag's value to the hash
doc.search("title").each do | title |
next if title.content == ""
hash["title"] = title.content
end

# add possible <meta> tag attribute's value to the hash
doc.search("meta").each do | meta |
name = get(meta, "name")
property = get(meta, "property")
charset = get(meta, "charset")
content = get(meta, "content")

if exists(name)
hash[name] = content
elsif exists(property)
hash[property] = content
elsif exists(charset)
hash["charset"] = charset
end
end

# add possible <link> tag attribute's value to the hash
doc.search("link").each do | link |
hash[get(link, "rel")] = get(link, "href")
end

hash
end

def log(msg)
Jekyll.logger.error "URL Metadata:", msg
end

def exists(obj)
!obj.nil? && obj != ""
end

def get(obj, attr)
obj.get_attribute(attr)
end

end # module Jekyll
end # module URLMetadata

Liquid::Template.register_filter(Jekyll::URLMetadata)
5 changes: 5 additions & 0 deletions lib/jekyll-url-metadata/version.rb
@@ -0,0 +1,5 @@
module Jekyll
module URLMetadata
VERSION = "1.0.0"
end # module Jekyll
end # module URLMetadata

0 comments on commit d1b8f96

Please sign in to comment.