diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..b46c417 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,27 @@ +name: Ruby + +on: + push: + branches: + - master + + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + name: Ruby ${{ matrix.ruby }} + strategy: + matrix: + ruby: + - '2.6.5' + + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run the default task + run: bundle exec rake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a97e381 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +/.bundle/ +/.yardoc +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ + +# rspec failure tracking +.rspec_status +*.gem +node_modules/ diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..34c5164 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--format documentation +--color +--require spec_helper diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..8826647 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,17 @@ +AllCops: + TargetRubyVersion: 2.6 + NewCops: enable + +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes + +Style/StringLiteralsInInterpolation: + Enabled: true + EnforcedStyle: double_quotes + +Layout/LineLength: + Max: 120 + +Naming/FileName: + Enabled: false \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..add520a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## [Unreleased] + +## [0.1.0] - 2024-06-06 + +- Initial release diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..a7a0c82 --- /dev/null +++ b/Gemfile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +# Specify your gem's dependencies in jekyll-crypto-donations.gemspec +gemspec + +gem "rake", "~> 13.0" + +gem "rspec", "~> 3.0" + +gem "rubocop", "~> 1.21" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..7e6bcb3 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,122 @@ +PATH + remote: . + specs: + jekyll-crypto-donations (0.1.0) + jekyll (~> 4.3) + +GEM + remote: https://rubygems.org/ + specs: + addressable (2.8.6) + public_suffix (>= 2.0.2, < 6.0) + ast (2.4.2) + colorator (1.1.0) + concurrent-ruby (1.3.1) + diff-lcs (1.5.1) + em-websocket (0.5.3) + eventmachine (>= 0.12.9) + http_parser.rb (~> 0) + eventmachine (1.2.7) + ffi (1.17.0) + forwardable-extended (2.6.0) + google-protobuf (3.23.4-x86_64-darwin) + google-protobuf (3.23.4-x86_64-linux) + http_parser.rb (0.8.0) + i18n (1.14.5) + concurrent-ruby (~> 1.0) + jekyll (4.3.3) + addressable (~> 2.4) + colorator (~> 1.0) + em-websocket (~> 0.5) + i18n (~> 1.0) + jekyll-sass-converter (>= 2.0, < 4.0) + jekyll-watch (~> 2.0) + kramdown (~> 2.3, >= 2.3.1) + kramdown-parser-gfm (~> 1.0) + liquid (~> 4.0) + mercenary (>= 0.3.6, < 0.5) + pathutil (~> 0.9) + rouge (>= 3.0, < 5.0) + safe_yaml (~> 1.0) + terminal-table (>= 1.8, < 4.0) + webrick (~> 1.7) + jekyll-sass-converter (3.0.0) + sass-embedded (~> 1.54) + jekyll-watch (2.2.1) + listen (~> 3.0) + json (2.7.2) + kramdown (2.4.0) + rexml + kramdown-parser-gfm (1.1.0) + kramdown (~> 2.0) + liquid (4.0.4) + listen (3.9.0) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) + mercenary (0.4.0) + parallel (1.24.0) + parser (3.3.2.0) + ast (~> 2.4.1) + racc + pathutil (0.16.2) + forwardable-extended (~> 2.6) + public_suffix (5.0.5) + racc (1.8.0) + rainbow (3.1.1) + rake (13.2.1) + rb-fsevent (0.11.2) + rb-inotify (0.11.1) + ffi (~> 1.0) + regexp_parser (2.9.2) + rexml (3.2.8) + strscan (>= 3.0.9) + rouge (3.30.0) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + rubocop (1.50.2) + json (~> 2.3) + parallel (~> 1.10) + parser (>= 3.2.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + ruby-progressbar (1.13.0) + safe_yaml (1.0.5) + sass-embedded (1.58.3) + google-protobuf (~> 3.21) + rake (>= 10.0.0) + strscan (3.1.0) + terminal-table (3.0.2) + unicode-display_width (>= 1.1.1, < 3) + unicode-display_width (2.5.0) + webrick (1.8.1) + +PLATFORMS + x86_64-darwin-21 + x86_64-linux + +DEPENDENCIES + bundler (~> 2.0) + jekyll-crypto-donations! + rake (~> 13.0) + rspec (~> 3.0) + rubocop (~> 1.21) + +BUNDLED WITH + 2.4.6 diff --git a/LICENSE b/LICENSE index 5775736..1e27f31 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -MIT License +The MIT License (MIT) Copyright (c) 2024 Eugene Leontev @@ -9,13 +9,13 @@ 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 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. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..abc7241 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Jekyll::CryptoDonations 🤑 + +## About + +The **Jekyll Crypto Donations** plugin is a simple and efficient solution for integrating cryptocurrency donations into Jekyll-generated websites. In the initial iteration, the plugin supports Bitcoin (BTC), Ethereum (ETH), and USDT (TRC-20). It allows website owners to display current donation amounts and provide easy access for visitors to contribute using these cryptocurrencies. The plugin is designed to be easy to install and configure, making it a seamless addition to any Jekyll site. By leveraging real-time API calls, it ensures that the displayed donation amounts are always up-to-date, providing transparency and encouraging more contributions. + +## Installation + +Add to your Gemfile: +```ruby +group :jekyll_plugins do + gem 'jekyll-crypto-donations' +end +``` + +## Usage + +Add donation addresses to your `_config.yaml` + +```yaml +crypto_donations: + btc_address: "YOUR_BTC_ADDRESS" + eth_address: "YOUR_ETH_ADDRESS" + usdt_address: "YOUR_USDT_TRC20_ADDRES" +``` + +## Development + +After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. + +To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). + +Use NodeJS version 20 LTS +```bash +$ nvm use 20 --lts +``` +install Typescrypt: `npm install typescript` + +Do not change `assets/js/crypto-donations/crypto-donations.js` manually, make changes with TS at `src/crypto-donations/crypto-donations.ts` and then run: +```bash +$ npx tsc +``` +local gem build: `gem build jekyll-crypto-donations.gemspec` + +## Contributing + +Bug reports and pull requests are welcome on GitHub at https://github.com/madmatvey/jekyll-crypto-donations. + +## License + +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..cca7175 --- /dev/null +++ b/Rakefile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) + +require "rubocop/rake_task" + +RuboCop::RakeTask.new + +task default: %i[spec rubocop] diff --git a/_includes/crypto_donations.html b/_includes/crypto_donations.html new file mode 100644 index 0000000..5defa9d --- /dev/null +++ b/_includes/crypto_donations.html @@ -0,0 +1,18 @@ + +
+

Support us with crypto-donations

+

Already :

+ +

Отправьте донат:

+ +
diff --git a/assets/js/crypto-donations/crypto-donations.js b/assets/js/crypto-donations/crypto-donations.js new file mode 100644 index 0000000..c2f54af --- /dev/null +++ b/assets/js/crypto-donations/crypto-donations.js @@ -0,0 +1,52 @@ +// assets/crypto-donations/crypto-donations.ts +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +function fetchCryptoData(url) { + return __awaiter(this, void 0, void 0, function* () { + const response = yield fetch(url); + return response.json(); + }); +} +export function getDonations(currency, address) { + return __awaiter(this, void 0, void 0, function* () { + try { + let response; + switch (currency) { + case 'btc': + const btcApiUrl = `https://api.blockcypher.com/v1/btc/main/addrs/${address}/balance`; + response = yield fetch(btcApiUrl); + if (!response.ok) + throw new Error('blockcypher api response was not ok'); + const btcData = yield response.json(); + return (btcData.total_received / 100000000).toFixed(8); + case 'eth': + const etcApiUrl = `https://api.ethplorer.io/getAddressInfo/${address}?apiKey=freekey`; + response = yield fetch(etcApiUrl); + if (!response.ok) + throw new Error('etherscan api response was not ok'); + const ethData = yield response.json(); + return (ethData.ETH.balance).toFixed(18); + case 'usdt': + response = yield fetch(`https://apilist.tronscan.org/api/account?address=${address}`); + if (!response.ok) + throw new Error('tronscan.org API response was not ok'); + const usdtData = yield response.json(); + const usdtToken = usdtData.trc20token_balances.find((token) => token.tokenAbbr === 'USDT'); + return (usdtToken.balance / 1000000).toFixed(2); // Balance USDT + default: + throw new Error('Unsupported currency'); + } + } + catch (error) { + console.error('Error fetching donation data:', error); + return '0.0'; + } + }); +} diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..0e36c6e --- /dev/null +++ b/bin/console @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "bundler/setup" +require "jekyll_crypto_donations" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +# (If you use this, don't forget to add pry to your Gemfile!) +# require "pry" +# Pry.start + +require "irb" +IRB.start(__FILE__) diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/jekyll-crypto-donations.gemspec b/jekyll-crypto-donations.gemspec new file mode 100644 index 0000000..97d665d --- /dev/null +++ b/jekyll-crypto-donations.gemspec @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require_relative "lib/jekyll-crypto-donations/version" + +Gem::Specification.new do |spec| + spec.name = "jekyll-crypto-donations" + spec.version = Jekyll::CryptoDonations::VERSION + spec.authors = ["madmatvey"] + spec.email = ["potehin@gmail.com"] + + spec.summary = "A Jekyll plugin for crypto donations" + spec.description = "This plugin allows you to collect and display cryptocurrency donations on your Jekyll site." + spec.homepage = "https://github.com/madmatvey/jekyll-crypto-donations" + spec.license = "MIT" + spec.required_ruby_version = ">= 2.6.0" + + spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" + + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/madmatvey/jekyll-crypto-donations.git" + spec.metadata["changelog_uri"] = "https://github.com/madmatvey/jekyll-crypto-donations/blob/master/CHANGELOG.md" + + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + # all_files = `git ls-files -z`.split("\x0") + spec.files = Dir["lib/**/*.rb"] + Dir["assets/js/**/*.js"] + spec.extra_rdoc_files = %w[README.md LICENSE] + spec.require_paths = ["lib"] + + # Uncomment to register a new dependency of your gem + # spec.add_dependency "example-gem", "~> 1.0" + spec.add_runtime_dependency "jekyll", "~> 4.3" + + spec.add_development_dependency "bundler", "~> 2.0" + spec.add_development_dependency "rake", "~> 13.0" + + # For more information and examples about making a new gem, check out our + # guide at: https://bundler.io/guides/creating_gem.html + spec.metadata["rubygems_mfa_required"] = "true" +end diff --git a/lib/jekyll-crypto-donations.rb b/lib/jekyll-crypto-donations.rb new file mode 100644 index 0000000..622a573 --- /dev/null +++ b/lib/jekyll-crypto-donations.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require "jekyll" +require "jekyll-crypto-donations/version" +# require "jekyll_crypto_donations/generator" + +module Jekyll + module CryptoDonations + # describe {% crypto_donations %} tag content + class DonationsTag < Liquid::Tag + def initialize(tag_name, text, tokens) + super + @text = text + end + + def render(context) + site_config = context.registers.fetch(:site).config + btc_address = site_config.dig("crypto_donations", "btc_address") + eth_address = site_config.dig("crypto_donations", "eth_address") + usdt_address = site_config.dig("crypto_donations", "usdt_address") + + <<~HTML +
+

Support Us with Crypto Donations

+

#{@text}

+
+

Bitcoin (BTC)

+

#{btc_address}

+

Loading...

+
+
+

Ethereum (ETH)

+

#{eth_address}

+

Loading...

+
+
+

USDT (TRC-20)

+

Address: #{usdt_address}

+

Loading...

+
+
+ + HTML + end + end + end +end + +Liquid::Template.register_tag("crypto_donations", Jekyll::CryptoDonations::DonationsTag) + +Jekyll::Hooks.register :site, :post_write do |site| + source = File.expand_path("../assets/js/crypto-donations/crypto-donations.js", __dir__) + destination = File.join(site.dest, "assets/js/crypto-donations/crypto-donations.js") + FileUtils.mkdir_p(File.dirname(destination)) + FileUtils.cp(source, destination) +end diff --git a/lib/jekyll-crypto-donations/version.rb b/lib/jekyll-crypto-donations/version.rb new file mode 100644 index 0000000..549bf11 --- /dev/null +++ b/lib/jekyll-crypto-donations/version.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Jekyll + module CryptoDonations + VERSION = "0.1.0" + end +end diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..379e301 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,24 @@ +{ + "name": "jekyll-crypto-donations", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "typescript": "^5.4.5" + } + }, + "node_modules/typescript": { + "version": "5.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", + "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..783918d --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "typescript": "^5.4.5" + } +} diff --git a/spec/jekyll/crypto_donations_spec.rb b/spec/jekyll/crypto_donations_spec.rb new file mode 100644 index 0000000..aa08fd2 --- /dev/null +++ b/spec/jekyll/crypto_donations_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +RSpec.describe Jekyll::CryptoDonations do + describe "gem things" do + it "has a version number" do + expect(described_class::VERSION).not_to be_nil + end + + it "has the proper superclass" do + expect(described_class::DonationsTag.superclass).to eq(Liquid::Tag) + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..8dfd334 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require "jekyll-crypto-donations" + +RSpec.configure do |config| + # Enable flags like --only-failures and --next-failure + config.example_status_persistence_file_path = ".rspec_status" + + # Disable RSpec exposing methods globally on `Module` and `main` + config.disable_monkey_patching! + + config.expect_with :rspec do |c| + c.syntax = :expect + end +end diff --git a/src/crypto-donations/crypto-donations.ts b/src/crypto-donations/crypto-donations.ts new file mode 100644 index 0000000..6e4472a --- /dev/null +++ b/src/crypto-donations/crypto-donations.ts @@ -0,0 +1,41 @@ +// assets/crypto-donations/crypto-donations.ts + +async function fetchCryptoData(url: string): Promise { + const response = await fetch(url); + return response.json(); +} + +export async function getDonations(currency: string, address: string): Promise { + try { + let response; + switch (currency) { + case 'btc': + const btcApiUrl = `https://api.blockcypher.com/v1/btc/main/addrs/${address}/balance` + response = await fetch(btcApiUrl); + if (!response.ok) throw new Error('blockcypher api response was not ok'); + const btcData = await response.json(); + return (btcData.total_received / 100000000).toFixed(8); + + case 'eth': + const etcApiUrl = `https://api.ethplorer.io/getAddressInfo/${address}?apiKey=freekey` + response = await fetch(etcApiUrl); + if (!response.ok) throw new Error('etherscan api response was not ok'); + const ethData = await response.json(); + return (ethData.ETH.balance).toFixed(18); + + case 'usdt': + response = await fetch(`https://apilist.tronscan.org/api/account?address=${address}`); + if (!response.ok) throw new Error('tronscan.org API response was not ok'); + const usdtData = await response.json(); + const usdtToken = usdtData.trc20token_balances.find((token: any) => token.tokenAbbr === 'USDT'); + return (usdtToken.balance / 1000000).toFixed(2); // Balance USDT + + default: + throw new Error('Unsupported currency'); + } + } catch (error) { + console.error('Error fetching donation data:', error); + return '0.0'; + } +} + diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..babc7a3 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "ES6", + "module": "ES6", + "outDir": "./assets/js", + "rootDir": "./src", + "strict": true + }, + "include": ["src/**/*.ts"] +} \ No newline at end of file