├── .rspec
├── spec
├── fixtures
│ ├── .gitignore
│ ├── _layouts
│ │ ├── default.html
│ │ ├── page.html
│ │ └── post.html
│ ├── index.markdown
│ ├── 404.html
│ ├── about.markdown
│ ├── Gemfile
│ ├── _posts
│ │ └── 2022-11-19-welcome-to-jekyll.markdown
│ └── _config.yml
├── jekyll
│ ├── mastodon_webfinger_spec.rb
│ └── mastodon_webfinger
│ │ └── generator_spec.rb
└── spec_helper.rb
├── Gemfile
├── bin
├── setup
└── console
├── lib
└── jekyll
│ ├── mastodon_webfinger
│ ├── version.rb
│ └── generator.rb
│ └── mastodon_webfinger.rb
├── .gitignore
├── Rakefile
├── .rubocop.yml
├── CHANGELOG.md
├── .github
└── workflows
│ └── build.yml
├── LICENSE
├── jekyll-mastodon_webfinger.gemspec
├── README.md
└── CODE_OF_CONDUCT.md
/.rspec:
--------------------------------------------------------------------------------
1 | --format documentation
2 | --color
3 | --require spec_helper
4 |
--------------------------------------------------------------------------------
/spec/fixtures/.gitignore:
--------------------------------------------------------------------------------
1 | _site
2 | .sass-cache
3 | .jekyll-cache
4 | .jekyll-metadata
5 | vendor
6 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source "https://rubygems.org"
4 |
5 | # Specify your gem's dependencies in jekyll-mastodon_webfinger.gemspec
6 | gemspec
7 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -euo pipefail
3 | IFS=$'\n\t'
4 | set -vx
5 |
6 | bundle install
7 |
8 | # Do any other automated setup that you need to do here
9 |
--------------------------------------------------------------------------------
/lib/jekyll/mastodon_webfinger/version.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module Jekyll
4 | module MastodonWebfinger
5 | VERSION = "1.0.2"
6 | end
7 | end
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.bundle/
2 | /.yardoc
3 | /_yardoc/
4 | /coverage/
5 | /doc/
6 | /pkg/
7 | /spec/reports/
8 | /tmp/
9 |
10 | # rspec failure tracking
11 | .rspec_status
12 |
13 | Gemfile.lock
--------------------------------------------------------------------------------
/spec/fixtures/_layouts/default.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/spec/fixtures/index.markdown:
--------------------------------------------------------------------------------
1 | ---
2 | # Feel free to add content and custom Front Matter to this file.
3 | # To modify the layout, see https://jekyllrb.com/docs/themes/#overriding-theme-defaults
4 |
5 | layout: default
6 | ---
7 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require "bundler/gem_tasks"
4 | require "rspec/core/rake_task"
5 |
6 | RSpec::Core::RakeTask.new(:spec)
7 |
8 | require "rubocop/rake_task"
9 |
10 | RuboCop::RakeTask.new
11 |
12 | task default: %i[spec rubocop]
13 |
--------------------------------------------------------------------------------
/spec/fixtures/_layouts/page.html:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | ---
4 |
5 |
6 |
9 |
10 |
11 | {{ content }}
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/lib/jekyll/mastodon_webfinger.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require "json"
4 | require "jekyll"
5 | require_relative "mastodon_webfinger/version"
6 | require_relative "mastodon_webfinger/generator"
7 |
8 | Jekyll::Hooks.register :site, :after_init do |site|
9 | keep_files = site.keep_files || []
10 | site.keep_files = keep_files.push(".well-known/webfinger").uniq
11 | end
12 |
--------------------------------------------------------------------------------
/.rubocop.yml:
--------------------------------------------------------------------------------
1 | require:
2 | - rubocop-rake
3 | - rubocop-rspec
4 |
5 | AllCops:
6 | TargetRubyVersion: 2.7
7 |
8 | Style/StringLiterals:
9 | Enabled: true
10 | EnforcedStyle: double_quotes
11 |
12 | Style/StringLiteralsInInterpolation:
13 | Enabled: true
14 | EnforcedStyle: double_quotes
15 |
16 | Layout/LineLength:
17 | Max: 120
18 |
19 | Style/SymbolArray:
20 | Enabled: false
21 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [Unreleased]
2 |
3 | ## [1.0.2] - 2022-11-25
4 |
5 | - Updates hook to use `site.keep_files` instead of `site.config["keep_files"]`
6 |
7 | ## [1.0.1] - 2022-11-20
8 |
9 | - Adds hook that includes `.well-known/webfinger` in the `keep_files` config
10 |
11 | ## [1.0.0] - 2022-11-19
12 |
13 | - Initial release
14 | - Generates `/.well-known/webfinger` file that points to a Mastodon profile defined in `_config.yml`
15 |
--------------------------------------------------------------------------------
/bin/console:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | require "bundler/setup"
5 | require "jekyll/mastodon_webfinger"
6 |
7 | # You can add fixtures and/or initialization code here to make experimenting
8 | # with your gem easier. You can also use a different console, if you like.
9 |
10 | # (If you use this, don't forget to add pry to your Gemfile!)
11 | # require "pry"
12 | # Pry.start
13 |
14 | require "irb"
15 | IRB.start(__FILE__)
16 |
--------------------------------------------------------------------------------
/spec/jekyll/mastodon_webfinger_spec.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | RSpec.describe Jekyll::MastodonWebfinger do
4 | it "has a version number" do
5 | expect(Jekyll::MastodonWebfinger::VERSION).not_to be nil
6 | end
7 |
8 | describe "hooks" do
9 | it "adds '.well-known/webfinger' to the keep_files config" do
10 | site = make_site
11 | expect(site.config["keep_files"]).to include(".well-known/webfinger")
12 | end
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/spec/fixtures/404.html:
--------------------------------------------------------------------------------
1 | ---
2 | permalink: /404.html
3 | layout: default
4 | ---
5 |
6 |
19 |
20 |
21 |
404
22 |
23 |
Page not found :(
24 |
The requested page could not be found.
25 |
26 |
--------------------------------------------------------------------------------
/spec/fixtures/about.markdown:
--------------------------------------------------------------------------------
1 | ---
2 | layout: page
3 | title: About
4 | permalink: /about/
5 | ---
6 |
7 | This is the base Jekyll theme. You can find out more info about customizing your Jekyll theme, as well as basic Jekyll usage documentation at [jekyllrb.com](https://jekyllrb.com/)
8 |
9 | You can find the source code for Minima at GitHub:
10 | [jekyll][jekyll-organization] /
11 | [minima](https://github.com/jekyll/minima)
12 |
13 | You can find the source code for Jekyll at GitHub:
14 | [jekyll][jekyll-organization] /
15 | [jekyll](https://github.com/jekyll/jekyll)
16 |
17 |
18 | [jekyll-organization]: https://github.com/jekyll
19 |
--------------------------------------------------------------------------------
/spec/fixtures/_layouts/post.html:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | ---
4 |
5 |
6 |
10 |
11 |
12 | {{ content }}
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: build
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 |
8 | pull_request:
9 |
10 | jobs:
11 | build:
12 | runs-on: ubuntu-latest
13 | name: Ruby ${{ matrix.ruby }}
14 | strategy:
15 | fail-fast: false
16 | matrix:
17 | ruby: [2.7, "3.0", 3.1]
18 | steps:
19 | - uses: actions/checkout@v3
20 | - name: Set up Ruby ${{ matrix.ruby }}
21 | uses: ruby/setup-ruby@v1
22 | with:
23 | ruby-version: ${{ matrix.ruby }}
24 | bundler-cache: true
25 | - name: "Install dependencies"
26 | run: bundle install
27 | - name: Run the tests
28 | run: bundle exec rake
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License Copyright (c) 2022 Phil Nash
2 |
3 | Permission is hereby granted, free of
4 | charge, to any person obtaining a copy of this software and associated
5 | documentation files (the "Software"), to deal in the Software without
6 | restriction, including without limitation the rights to use, copy, modify, merge,
7 | publish, distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to the
9 | following conditions:
10 |
11 | The above copyright notice and this permission notice
12 | (including the next paragraph) shall be included in all copies or substantial
13 | portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
18 | EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require "simplecov"
4 |
5 | SimpleCov.start do
6 | add_filter(/spec/)
7 | end
8 |
9 | require "jekyll/mastodon_webfinger"
10 |
11 | SOURCE_DIR = File.expand_path("fixtures", __dir__)
12 | DEST_DIR = File.expand_path("dest", __dir__)
13 |
14 | def source_dir(*files)
15 | File.join(SOURCE_DIR, *files)
16 | end
17 |
18 | def dest_dir(*files)
19 | File.join(DEST_DIR, *files)
20 | end
21 |
22 | CONFIG_DEFAULTS = {
23 | "source" => source_dir,
24 | "destination" => dest_dir,
25 | "title" => "Your awesome title",
26 | "email" => "your-email@domain.com",
27 | "description" => "A description",
28 | "baseurl" => "",
29 | "url" => "http://yourdomain.com",
30 | "twitter_username" => "jekyllrb",
31 | "github_username" => "jekyll",
32 | "markdown" => "kramdown"
33 | }.freeze
34 |
35 | RSpec.configure do |config|
36 | # Enable flags like --only-failures and --next-failure
37 | config.example_status_persistence_file_path = ".rspec_status"
38 |
39 | # Disable RSpec exposing methods globally on `Module` and `main`
40 | config.disable_monkey_patching!
41 |
42 | config.expect_with :rspec do |c|
43 | c.syntax = :expect
44 | end
45 |
46 | def make_site(opts = {})
47 | config = Jekyll::Utils.deep_merge_hashes(opts, CONFIG_DEFAULTS)
48 | site_config = Jekyll.configuration(config)
49 | Jekyll::Site.new(site_config)
50 | end
51 | end
52 |
--------------------------------------------------------------------------------
/spec/fixtures/Gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source "https://rubygems.org"
4 | # Hello! This is where you manage which Jekyll version is used to run.
5 | # When you want to use a different version, change it below, save the
6 | # file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
7 | #
8 | # bundle exec jekyll serve
9 | #
10 | # This will help ensure the proper Jekyll version is running.
11 | # Happy Jekylling!
12 | gem "jekyll", "~> 4.3.1"
13 | # This is the default theme for new Jekyll sites. You may change this to anything you like.
14 | gem "minima", "~> 2.5"
15 | # If you want to use GitHub Pages, remove the "gem "jekyll"" above and
16 | # uncomment the line below. To upgrade, run `bundle update github-pages`.
17 | # gem "github-pages", group: :jekyll_plugins
18 | # If you have any plugins, put them here!
19 | group :jekyll_plugins do
20 | gem "jekyll-feed", "~> 0.12"
21 | end
22 |
23 | # Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
24 | # and associated library.
25 | platforms :mingw, :x64_mingw, :mswin, :jruby do
26 | gem "tzinfo", ">= 1", "< 3"
27 | gem "tzinfo-data"
28 | end
29 |
30 | # Performance-booster for watching directories on Windows
31 | gem "wdm", "~> 0.1.1", platforms: [:mingw, :x64_mingw, :mswin]
32 |
33 | # Lock `http_parser.rb` gem to `v0.6.x` on JRuby builds since newer versions of the gem
34 | # do not have a Java counterpart.
35 | gem "http_parser.rb", "~> 0.6.0", platforms: [:jruby]
36 |
--------------------------------------------------------------------------------
/spec/fixtures/_posts/2022-11-19-welcome-to-jekyll.markdown:
--------------------------------------------------------------------------------
1 | ---
2 | layout: post
3 | title: "Welcome to Jekyll!"
4 | date: 2022-11-19 10:51:19 +0800
5 | categories: jekyll update
6 | ---
7 | You’ll find this post in your `_posts` directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run `jekyll serve`, which launches a web server and auto-regenerates your site when a file is updated.
8 |
9 | Jekyll requires blog post files to be named according to the following format:
10 |
11 | `YEAR-MONTH-DAY-title.MARKUP`
12 |
13 | Where `YEAR` is a four-digit number, `MONTH` and `DAY` are both two-digit numbers, and `MARKUP` is the file extension representing the format used in the file. After that, include the necessary front matter. Take a look at the source for this post to get an idea about how it works.
14 |
15 | Jekyll also offers powerful support for code snippets:
16 |
17 | {% highlight ruby %}
18 | def print_hi(name)
19 | puts "Hi, #{name}"
20 | end
21 | print_hi('Tom')
22 | #=> prints 'Hi, Tom' to STDOUT.
23 | {% endhighlight %}
24 |
25 | Check out the [Jekyll docs][jekyll-docs] for more info on how to get the most out of Jekyll. File all bugs/feature requests at [Jekyll’s GitHub repo][jekyll-gh]. If you have questions, you can ask them on [Jekyll Talk][jekyll-talk].
26 |
27 | [jekyll-docs]: https://jekyllrb.com/docs/home
28 | [jekyll-gh]: https://github.com/jekyll/jekyll
29 | [jekyll-talk]: https://talk.jekyllrb.com/
30 |
--------------------------------------------------------------------------------
/jekyll-mastodon_webfinger.gemspec:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require_relative "lib/jekyll/mastodon_webfinger/version"
4 |
5 | Gem::Specification.new do |spec|
6 | spec.name = "jekyll-mastodon_webfinger"
7 | spec.version = Jekyll::MastodonWebfinger::VERSION
8 | spec.authors = ["Phil Nash"]
9 | spec.email = ["philnash@gmail.com"]
10 |
11 | spec.summary = "Use your Jekyll site and domain to forward to your Mastodon profile"
12 | spec.description = "Allows you to use your own custom domain to point to your" \
13 | "Mastodon profile by adding a /.well-known/webfinger file to your site output"
14 | spec.homepage = "https://github.com/philnash/jekyll-mastodon_webfinger"
15 | spec.required_ruby_version = ">= 2.7.0"
16 | spec.license = "MIT"
17 |
18 | spec.metadata["homepage_uri"] = spec.homepage
19 | spec.metadata["source_code_uri"] = spec.homepage
20 | spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
21 |
22 | # Specify which files should be added to the gem when it is released.
23 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24 | spec.files = Dir.chdir(__dir__) do
25 | `git ls-files -z`.split("\x0").reject do |f|
26 | (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27 | end
28 | end
29 | spec.require_paths = ["lib"]
30 |
31 | spec.add_dependency "jekyll", ">= 3.0", "< 5.0"
32 |
33 | spec.add_development_dependency "rake", "~> 13.0"
34 | spec.add_development_dependency "rspec", "~> 3.0"
35 | spec.add_development_dependency "rubocop", "~> 1.21"
36 | spec.add_development_dependency "rubocop-rake", "~> 0.6"
37 | spec.add_development_dependency "rubocop-rspec", "~> 2.15"
38 | spec.add_development_dependency "simplecov", "~> 0.21"
39 | end
40 |
--------------------------------------------------------------------------------
/lib/jekyll/mastodon_webfinger/generator.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module Jekyll
4 | module MastodonWebfinger
5 | # A Jekyll Generator that creates a `/.well-known/webfinger` file in the
6 | # site output that points to your Mastodon identity
7 | class Generator < Jekyll::Generator
8 | def generate(site)
9 | destination = site.config["destination"]
10 | mastodon = site.config["mastodon"]
11 | return unless mastodon && mastodon["username"] && mastodon["instance"]
12 |
13 | username = mastodon["username"]
14 | instance = mastodon["instance"]
15 |
16 | directory = create_directory(destination)
17 | write_webfinger_file(directory, username, instance)
18 | end
19 |
20 | private
21 |
22 | def create_directory(destination)
23 | directory = File.join(destination, ".well-known")
24 | FileUtils.mkdir_p(directory)
25 | directory
26 | end
27 |
28 | def write_webfinger_file(directory, username, instance)
29 | filename = File.join(directory, "webfinger")
30 | File.open(filename, "w") do |file|
31 | file.write webfinger_json(username, instance)
32 | end
33 | end
34 |
35 | # rubocop:disable Metrics/MethodLength
36 | def webfinger_json(username, instance)
37 | {
38 | subject: "acct:#{username}@#{instance}",
39 | aliases: [
40 | "https://#{instance}/@#{username}",
41 | "https://#{instance}/users/#{username}"
42 | ],
43 | links: [
44 | {
45 | rel: "http://webfinger.net/rel/profile-page",
46 | type: "text/html",
47 | href: "https://#{instance}/@#{username}"
48 | },
49 | {
50 | rel: "self",
51 | type: "application/activity+json",
52 | href: "https://#{instance}/users/#{username}"
53 | },
54 | {
55 | rel: "http://ostatus.org/schema/1.0/subscribe",
56 | template: "https://#{instance}/authorize_interaction?uri={uri}"
57 | }
58 | ]
59 | }.to_json
60 | end
61 | # rubocop:enable Metrics/MethodLength
62 | end
63 | end
64 | end
65 |
--------------------------------------------------------------------------------
/spec/fixtures/_config.yml:
--------------------------------------------------------------------------------
1 | # Welcome to Jekyll!
2 | #
3 | # This config file is meant for settings that affect your whole blog, values
4 | # which you are expected to set up once and rarely edit after that. If you find
5 | # yourself editing this file very often, consider using Jekyll's data files
6 | # feature for the data you need to update frequently.
7 | #
8 | # For technical reasons, this file is *NOT* reloaded automatically when you use
9 | # 'bundle exec jekyll serve'. If you change this file, please restart the server process.
10 | #
11 | # If you need help with YAML syntax, here are some quick references for you:
12 | # https://learn-the-web.algonquindesign.ca/topics/markdown-yaml-cheat-sheet/#yaml
13 | # https://learnxinyminutes.com/docs/yaml/
14 | #
15 | # Site settings
16 | # These are used to personalize your new site. If you look in the HTML files,
17 | # you will see them accessed via {{ site.title }}, {{ site.email }}, and so on.
18 | # You can create any custom variable you would like, and they will be accessible
19 | # in the templates via {{ site.myvariable }}.
20 |
21 | title: Your awesome title
22 | email: your-email@example.com
23 | description: >- # this means to ignore newlines until "baseurl:"
24 | Write an awesome description for your new site here. You can edit this
25 | line in _config.yml. It will appear in your document head meta (for
26 | Google search results) and in your feed.xml site description.
27 | baseurl: "" # the subpath of your site, e.g. /blog
28 | url: "" # the base hostname & protocol for your site, e.g. http://example.com
29 | twitter_username: jekyllrb
30 | github_username: jekyll
31 | # Build settings
32 | # theme: minima
33 | # plugins:
34 | # - jekyll-feed
35 | # Exclude from processing.
36 | # The following items will not be processed, by default.
37 | # Any item listed under the `exclude:` key here will be automatically added to
38 | # the internal "default list".
39 | #
40 | # Excluded items can be processed by explicitly listing the directories or
41 | # their entries' file path in the `include:` list.
42 | #
43 | # exclude:
44 | # - .sass-cache/
45 | # - .jekyll-cache/
46 | # - gemfiles/
47 | # - Gemfile
48 | # - Gemfile.lock
49 | # - node_modules/
50 | # - vendor/bundle/
51 | # - vendor/cache/
52 | # - vendor/gems/
53 | # - vendor/ruby/
54 |
--------------------------------------------------------------------------------
/spec/jekyll/mastodon_webfinger/generator_spec.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | RSpec.describe Jekyll::MastodonWebfinger::Generator do
4 | describe "without a mastodon config setting" do
5 | let(:site) { make_site }
6 |
7 | before { site.process }
8 | after { FileUtils.rm_r(dest_dir) }
9 |
10 | it "does nothing" do
11 | generator = described_class.new
12 | generator.generate(site)
13 | expect(Dir.exist?(dest_dir(".well-known"))).to be(false)
14 | end
15 | end
16 |
17 | describe "with a mastodon username but no instance" do
18 | let(:site) { make_site("mastodon" => { "username" => "philnash" }) }
19 |
20 | before { site.process }
21 | after { FileUtils.rm_r(dest_dir) }
22 |
23 | it "does nothing" do
24 | generator = described_class.new
25 | generator.generate(site)
26 | expect(Dir.exist?(dest_dir(".well-known"))).to be(false)
27 | end
28 | end
29 |
30 | describe "with a mastodon instance but no username" do
31 | let(:site) { make_site("mastodon" => { "instance" => "mastodon.social" }) }
32 |
33 | before { site.process }
34 | after { FileUtils.rm_r(dest_dir) }
35 |
36 | it "does nothing" do
37 | generator = described_class.new
38 | generator.generate(site)
39 | expect(Dir.exist?(dest_dir(".well-known"))).to be(false)
40 | end
41 | end
42 |
43 | describe "with a mastodon username and instance" do
44 | let(:username) { "philnash" }
45 | let(:instance) { "mastodon.social" }
46 | let(:generator) { described_class.new }
47 | let(:webfinger_file) { dest_dir(".well-known", "webfinger") }
48 |
49 | before do
50 | site = make_site("mastodon" => { "username" => username, "instance" => instance })
51 | site.process
52 | generator.generate(site)
53 | end
54 |
55 | after { FileUtils.rm_r(dest_dir) }
56 |
57 | it "generates a .well-known directory" do
58 | expect(Dir.exist?(dest_dir(".well-known"))).to be(true)
59 | end
60 |
61 | it "generates a webfinger file" do
62 | expect(File.exist?(webfinger_file)).to be(true)
63 | end
64 |
65 | describe "the webfinger file" do
66 | let(:webfinger) do
67 | file = File.open(webfinger_file)
68 | contents = file.read
69 | file.close
70 | JSON.parse(contents)
71 | end
72 |
73 | it "has a subject" do
74 | expect(webfinger["subject"]).to eq("acct:#{username}@#{instance}")
75 | end
76 |
77 | it "has two aliases" do
78 | expect(webfinger["aliases"]).to include("https://#{instance}/@#{username}", "https://#{instance}/users/#{username}")
79 | end
80 |
81 | it "has a link for a profile page" do
82 | expect(webfinger["links"]).to include(
83 | "rel" => "http://webfinger.net/rel/profile-page",
84 | "type" => "text/html",
85 | "href" => "https://#{instance}/@#{username}"
86 | )
87 | end
88 |
89 | it "has a link for the JSON activity feed" do
90 | expect(webfinger["links"]).to include(
91 | "rel" => "self",
92 | "type" => "application/activity+json",
93 | "href" => "https://#{instance}/users/#{username}"
94 | )
95 | end
96 |
97 | it "has a link for ostatus" do
98 | expect(webfinger["links"]).to include(
99 | "rel" => "http://ostatus.org/schema/1.0/subscribe",
100 | "template" => "https://#{instance}/authorize_interaction?uri={uri}"
101 | )
102 | end
103 | end
104 | end
105 | end
106 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # `Jekyll::MastodonWebfinger`
2 |
3 | Use your Jekyll website domain as an alias for your Mastodon username
4 |
5 | This is a [Jekyll](https://jekyllrb.com/) plugin that adds a [WebFinger](https://webfinger.net/) file to your site, allowing you to use your own domain as an alias to help others discover your [Mastodon](https://joinmastodon.org/) profile.
6 |
7 | Try it out
8 |
9 | Search Mastodon for `@phil@philna.sh` and you will find my Mastodon profile.
10 |
11 | * [What?](#what)
12 | * [Alternatives](#alternatives)
13 | * [How to use](#how-to-use)
14 | * [Config](#config)
15 | * [Drawbacks](#drawbacks)
16 | * [Development](#development)
17 | * [Contributing](#contributing)
18 | * [Code of Conduct](#code-of-conduct)
19 | * [License](#license)
20 |
21 | ## What?
22 |
23 | You may be tempted to run your own Mastodon instance so that you can use your own domain. If you don't want the work of managing a server you can instead use your domain as an alias to point to your Mastodon profile.
24 |
25 | This uses [WebFinger](https://webfinger.net/), which is a way to attach information to an email address or other online resource. In this case you can point email addresses on your own domain to your Mastodon profile.
26 |
27 | For example, I have a Mastodon profile at [@philnash@mastodon.social](https://mastodon.social/@philnash). If I add this plugin to my Jekyll site at https://philna.sh and set the username to `philnash` and the instance to `mastodon.social`, then you will be able to find my account by searching for `phil@philna.sh` in any Mastodon instance.
28 |
29 | For a more in depth explanation, check out [Mastodon on your own domain without hosting a server
30 | by Maarten Balliauw](https://blog.maartenballiauw.be/post/2022/11/05/mastodon-own-donain-without-hosting-server.html).
31 |
32 | ### Alternatives
33 |
34 | * @dkundel's [netlify-plugin-mastodon-alias](https://github.com/dkundel/netlify-plugin-mastodon-alias)
35 | * Lindsay Kwardell explains [how to integrate Mastodon with Astro](https://www.lindsaykwardell.com/blog/integrate-mastodon-with-astro)
36 |
37 | ## How to use
38 |
39 | Add the gem to your Jekyll site's `Gemfile` by executing:
40 |
41 | $ bundle add jekyll-mastodon_webfinger
42 |
43 | Or by opening the `Gemfile`, adding:
44 |
45 | gem "jekyll-mastodon_webfinger"
46 |
47 | and then running `bundle install`.
48 |
49 | ### Config
50 |
51 | You need to add two things to your `_config.yml` file.
52 |
53 | 1. Add your Mastodon account details. For example:
54 |
55 | ```yml
56 | mastodon:
57 | username: philnash
58 | instance: mastodon.social
59 | ```
60 |
61 | 2. Add `jekyll/mastodon_webfinger` to the `plugins` list:
62 |
63 | ```yml
64 | plugins:
65 | - jekyll/mastodon_webfinger
66 | ```
67 |
68 | Next time you build your Jekyll site, you will find a `/.well-known/` directory in the output with a `webfinger` file that contains the required JSON.
69 |
70 | ### Drawbacks
71 |
72 | Since this generates a static file, this actually acts like a catch-all email address. `@anything@yourdomain.com` will match and point to the Mastodon profile your define.
73 |
74 | ## Development
75 |
76 | 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.
77 |
78 | 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).
79 |
80 | ## Contributing
81 |
82 | Bug reports and pull requests are welcome on GitHub at https://github.com/philnash/jekyll-mastodon_webfinger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/philnash/jekyll-mastodon_webfinger/blob/main/CODE_OF_CONDUCT.md).
83 |
84 | ## Code of Conduct
85 |
86 | Everyone interacting in the Jekyll::MastodonWebfinger project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/philnash/jekyll-mastodon_webfinger/blob/main/CODE_OF_CONDUCT.md).
87 |
88 | ## License
89 |
90 | The gem is available as open source under the terms of the [MIT License](https://github.com/philnash/jekyll-mastodon_webfinger/blob/main/LICENSE).
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | 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.
6 |
7 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8 |
9 | ## Our Standards
10 |
11 | Examples of behavior that contributes to a positive environment for our community include:
12 |
13 | * Demonstrating empathy and kindness toward other people
14 | * Being respectful of differing opinions, viewpoints, and experiences
15 | * Giving and gracefully accepting constructive feedback
16 | * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17 | * Focusing on what is best not just for us as individuals, but for the overall community
18 |
19 | Examples of unacceptable behavior include:
20 |
21 | * The use of sexualized language or imagery, and sexual attention or
22 | advances of any kind
23 | * Trolling, insulting or derogatory comments, and personal or political attacks
24 | * Public or private harassment
25 | * Publishing others' private information, such as a physical or email
26 | address, without their explicit permission
27 | * Other conduct which could reasonably be considered inappropriate in a
28 | professional setting
29 |
30 | ## Enforcement Responsibilities
31 |
32 | 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.
33 |
34 | 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.
35 |
36 | ## Scope
37 |
38 | 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.
39 |
40 | ## Enforcement
41 |
42 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at philnash@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43 |
44 | All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45 |
46 | ## Enforcement Guidelines
47 |
48 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49 |
50 | ### 1. Correction
51 |
52 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53 |
54 | **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.
55 |
56 | ### 2. Warning
57 |
58 | **Community Impact**: A violation through a single incident or series of actions.
59 |
60 | **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.
61 |
62 | ### 3. Temporary Ban
63 |
64 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65 |
66 | **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.
67 |
68 | ### 4. Permanent Ban
69 |
70 | **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.
71 |
72 | **Consequence**: A permanent ban from any sort of public interaction within the community.
73 |
74 | ## Attribution
75 |
76 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78 |
79 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80 |
81 | [homepage]: https://www.contributor-covenant.org
82 |
83 | For answers to common questions about this code of conduct, see the FAQ at
84 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
85 |
--------------------------------------------------------------------------------