bridgetown_internal_markdown_links 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a5af81b6852818436a175b23ee682d48ee8f65c7bf2e84bd9c464e685542b22c
4
+ data.tar.gz: 28d22f8b05e5cdada85060e0a039a25b964ddad08580ef06211d69daed0aea39
5
+ SHA512:
6
+ metadata.gz: 8959cb5ec3cc01b821eac074690714bc568de4d770098064003d364dbdd4c05091e0a1933f7b8809e33b7c067853f02dfb879de9e6210840d7a36e7a22bd0b94
7
+ data.tar.gz: 7fc681db4d1b6abaf9e090e7813a99f2c6482f929f7087d4adf338d6a3ec8ab1c1f52b9f0c1044d174387f96771d635e838b8b4cc446f2c84a11ad39a65c0c0f
data/.gitignore ADDED
@@ -0,0 +1,40 @@
1
+ /vendor
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+ *.gem
17
+ Gemfile.lock
18
+ .bundle
19
+ .ruby-version
20
+
21
+ # Node
22
+ node_modules
23
+ .npm
24
+ .node_repl_history
25
+
26
+ # Yarn
27
+ yarn-error.log
28
+ yarn-debug.log*
29
+ .pnp/
30
+ .pnp.js
31
+
32
+ # Yarn Integrity file
33
+ .yarn-integrity
34
+
35
+ test/dest
36
+ .bridgetown-metadata
37
+ .bridgetown-cache
38
+ .bridgetown-webpack
39
+
40
+ .env
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ require: rubocop-bridgetown
2
+
3
+ inherit_gem:
4
+ rubocop-bridgetown: .rubocop.yml
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.7
8
+
9
+ Exclude:
10
+ - .gitignore
11
+ - .rubocop.yml
12
+ - "*.gemspec"
13
+
14
+ - Gemfile.lock
15
+ - CHANGELOG.md
16
+ - LICENSE.txt
17
+ - README.md
18
+ - Rakefile
19
+ - bridgetown.automation.rb
20
+
21
+ - script/**/*
22
+ - test/fixtures/**/*
23
+ - vendor/**/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2023-03-24
9
+
10
+ - First version
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
5
+
6
+ gem "bridgetown", ENV["BRIDGETOWN_VERSION"] if ENV["BRIDGETOWN_VERSION"]
7
+
8
+ # group :test do
9
+ # gem "minitest"
10
+ # gem "minitest-profile"
11
+ # gem "minitest-reporters"
12
+ # end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020-present
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # 🔗 Bridgetown Internal Markdown links
2
+
3
+ This plugin allows you to write paths in your markdown, like so:
4
+
5
+ `[Check out the docs](_pages/docs.erb)`.
6
+
7
+ Instead of the page's absolute url (ex. "/docs/"). If the slug is changed for that page, you don't have to go and do a find/replace throughout your site.
8
+
9
+ This plugin uses Bridgetown's `url_for()` helper in the background.
10
+
11
+
12
+ ## Installation
13
+
14
+ Run this command to add this plugin to your site's Gemfile:
15
+
16
+ ```shell
17
+ bundle add bridgetown_internal_markdown_links
18
+ ```
19
+
20
+ Then add the initializer to your configuration in `config/initializers.rb`:
21
+
22
+ ```ruby
23
+ init :bridgetown_internal_markdown_links
24
+ ```
25
+
26
+
27
+ ## Usage
28
+
29
+ Link parsing is opt-in per collection.
30
+
31
+ ### Configuration
32
+
33
+ Add the following in your `config/initializers.rb`:
34
+
35
+ ```ruby
36
+ config.internal_markdown_links.collections = ["posts", "docs"]
37
+ ```
38
+
39
+ Parsing of internal links is now happening for the collections “posts” and “docs”.
40
+
41
+
42
+ ### Disable per file
43
+
44
+ Set `internal_markdown_links: false` in the frontmatter.
45
+
46
+
47
+ ## Testing (TBD)
48
+
49
+ * Run `bundle exec rake test` to run the test suite
50
+ * Or run `script/cibuild` to validate with Rubocop and Minitest together.
51
+
52
+
53
+ ## Sponsored By [Spinal](https://spinalcms.com/cms-for-bridgetown/)
54
+
55
+ <a href="https://spinalcms.com/cms-for-bridgetown/" target="_blank">
56
+ <img src="https://user-images.githubusercontent.com/988051/183079316-af747ef2-42a9-47d8-9a0c-488ed4b6a689.jpg" alt="Spinal CMS logo" width="200"/>
57
+ </a>
58
+
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it (https://github.com/SpinalCMS/bridgetown-internal-markdown-links/fork)
63
+ 2. Clone the fork using `git clone` to your local development machine.
64
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 5. Push to the branch (`git push origin my-new-feature`)
67
+ 6. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/test_*.rb"]
8
+ t.warning = false
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/bridgetown_internal_markdown_links/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bridgetown_internal_markdown_links"
7
+ spec.version = BridgetownInternalMarkdownLinks::VERSION
8
+ spec.author = "Spinal Developers"
9
+ spec.email = "developers@spinalcms.com"
10
+ spec.summary = "Parse internal links in markdown files"
11
+ spec.homepage = "https://github.com/spinalcms/bridgetown-internal-markdown-links"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features)/!) }
15
+ spec.test_files = spec.files.grep(%r!^test/!)
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.required_ruby_version = ">= 2.7.0"
19
+
20
+ spec.add_dependency "bridgetown", ">= 1.2.0", "< 2.0"
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rake", ">= 13.0"
24
+ spec.add_development_dependency "rubocop-bridgetown", "~> 0.3"
25
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownInternalMarkdownLinks
4
+ class Builder < Bridgetown::Builder
5
+ MARKDOWN_LINK_REGEX = %r{\[([^\]]+)\]\(([^)]+)\)}.freeze
6
+
7
+ def build
8
+ parseable_collections.each do |collection|
9
+ Bridgetown.logger.info "Bridgetown Internal Markdown Links:",
10
+ "Parsing links for #{collection}"
11
+
12
+ hook collection, :pre_render do |resource|
13
+ next if resource.data.internal_markdown_links == false
14
+
15
+ parse_internal_links(resource)
16
+ end
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def parseable_collections
23
+ config.internal_markdown_links.collections.map(&:to_sym)
24
+ end
25
+
26
+ def parse_internal_links(resource)
27
+ resource.content.gsub!(MARKDOWN_LINK_REGEX) do
28
+ match = Regexp.last_match
29
+ label = match[1]
30
+ link = match[2]
31
+
32
+ if excluding?(link)
33
+ "[#{label}](#{link})"
34
+ else
35
+ "[#{label}](#{Bridgetown::RubyTemplateView::Helpers.new(resource, site).url_for(link)})"
36
+ end
37
+ end
38
+ end
39
+
40
+ def excluding?(link)
41
+ (link&.starts_with?("http") && !link&.include?(site.config.url)) ||
42
+ link&.starts_with?("#") ||
43
+ link&.starts_with?("mailto:") ||
44
+ link&.ends_with?("jpg")
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownInternalMarkdownLinks
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bridgetown"
4
+ require "bridgetown_internal_markdown_links/builder"
5
+
6
+ Bridgetown.initializer :bridgetown_internal_markdown_links do |config|
7
+ config.internal_markdown_links ||= {}
8
+ config.internal_markdown_links.collections ||= []
9
+
10
+ config.builder BridgetownInternalMarkdownLinks::Builder
11
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bridgetown_internal_markdown_links
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Spinal Developers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bridgetown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '13.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '13.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rubocop-bridgetown
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.3'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.3'
75
+ description:
76
+ email: developers@spinalcms.com
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - ".gitignore"
82
+ - ".rubocop.yml"
83
+ - CHANGELOG.md
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bridgetown_internal_markdown_links.gemspec
89
+ - lib/bridgetown_internal_markdown_links.rb
90
+ - lib/bridgetown_internal_markdown_links/builder.rb
91
+ - lib/bridgetown_internal_markdown_links/version.rb
92
+ homepage: https://github.com/spinalcms/bridgetown-internal-markdown-links
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 2.7.0
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.4.7
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Parse internal links in markdown files
115
+ test_files: []