├── Gemfile ├── LICENSE ├── README.md ├── jekyll-regex-replace.gemspec └── lib └── jekyll-regex-replace.rb /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Josh Davenport 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jekyll Regex Replace 2 | Simple module to allow using regular expression replacing via liquid filters 3 | 4 | 5 | ``` 6 | {{ '1-a-test' | regex_replace: '^[0-9]*-', '' }} 7 | ``` 8 | 9 | or 10 | 11 | ``` 12 | {{ '1-a-test-2-a-test' | regex_replace_once: '[0-9]*-', '' }} 13 | ``` 14 | 15 | ## Install 16 | 17 | Add the following to your `Gemfile` and then run `bundle install`. 18 | 19 | ``` 20 | gem 'jekyll-regex-replace' 21 | ``` 22 | -------------------------------------------------------------------------------- /jekyll-regex-replace.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |spec| 2 | spec.name = "jekyll-regex-replace" 3 | spec.version = '1.1.0' 4 | spec.authors = ["Josh Davenport"] 5 | spec.email = ["josh@joshdavenport.co.uk"] 6 | spec.summary = 'Simple module to allow using regular expression replacing via liquid filters' 7 | spec.homepage = 'https://github.com/joshdavenport/jekyll-regex-replace' 8 | spec.license = "MIT" 9 | spec.files = `git ls-files -z`.split("\x0") 10 | spec.require_paths = ['lib'] 11 | 12 | spec.required_ruby_version = '>= 2.1.0' 13 | 14 | spec.add_development_dependency 'jekyll', '>= 3.1' 15 | end 16 | -------------------------------------------------------------------------------- /lib/jekyll-regex-replace.rb: -------------------------------------------------------------------------------- 1 | require 'liquid' 2 | 3 | module Jekyll 4 | module RegexReplace 5 | def regex_replace(str, regex_search, value_replace) 6 | regex = /#{regex_search}/ 7 | return str.gsub(regex, value_replace) 8 | end 9 | 10 | def regex_replace_once(str, regex_search, value_replace) 11 | regex = /#{regex_search}/ 12 | return str.sub(regex, value_replace) 13 | end 14 | end 15 | end 16 | 17 | Liquid::Template.register_filter(Jekyll::RegexReplace) 18 | --------------------------------------------------------------------------------