zolaposta 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cb7a1b23cd76a7b1e3b30d9dc523c3ac226b5b83a36683b6e7598281421528ec
4
+ data.tar.gz: 0f5bb35a35b2136c626c83323c7b535d8478ce8ff9707659be905fe291a3b142
5
+ SHA512:
6
+ metadata.gz: 700702e2dde5316414c032cafdbb91d7cc3a45452c3cb925f1c245eadcad1da55dbf78a1b89e3d7eed97a1d423e3736a9d1d3a1922c56e9232734df6b321a0cc
7
+ data.tar.gz: be8056fefc21047792857de67e21ca6f01a82305f32c7217b160d807160e6c0229c7c9397150334ed03e9f5b47844287a00028e9a3ddd9be100558fb0dd55fba
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 np
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Zolaposta
2
+
3
+ A ruby gem to generate frontmatter for a [Zola]('https://www.getzola.org/') blog.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add zolaposta
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install zolaposta-0.1.0.gem
14
+
15
+ ## Usage
16
+
17
+ Install the gem and run `zolaposta`
18
+
19
+ ## Development
20
+
21
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
22
+
23
+ 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).
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on Codeberg at https://github.com/nullpotential/zolaposta.
28
+
29
+ ## License
30
+
31
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/exe/zolaposta ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "zolaposta"
4
+
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zolaposta
4
+ VERSION = "0.1.0"
5
+ end
data/lib/zolaposta.rb ADDED
@@ -0,0 +1,91 @@
1
+ require 'toml-rb'
2
+ require 'date'
3
+ require 'colorize'
4
+
5
+ def generate_frontmatter(title, description, tags)
6
+ frontmatter = {
7
+ 'date' => Date.today.strftime('%Y-%m-%d')
8
+ }
9
+
10
+ frontmatter['title'] = title unless title.empty?
11
+
12
+ frontmatter['description'] = description unless description.empty?
13
+
14
+ frontmatter['taxonomies'] = { 'tags' => tags } unless tags.empty?
15
+
16
+ TomlRB.dump(frontmatter)
17
+ end
18
+
19
+ def get_user_input(prompt)
20
+ print prompt.colorize(color: :blue, mode: :bold)
21
+ gets.chomp
22
+ end
23
+
24
+ def get_tags_from_user()
25
+ tags = []
26
+
27
+ loop do
28
+ tag = get_user_input('Enter a tag (press enter to add another tag, or leave blank if done): ')
29
+ break if tag.empty?
30
+
31
+ tags << tag
32
+ end
33
+
34
+ tags
35
+ end
36
+
37
+ def cancel_operation()
38
+ puts 'Operation cancelled. Exiting...'.colorize(:red)
39
+ exit
40
+ end
41
+
42
+ puts "\n--------------------------------".colorize(:green)
43
+ puts "Welcome to zolaposta!".colorize(:green)
44
+ puts "This app allows you to generate frontmatter for your blog posts.".colorize(:green)
45
+ puts "You can type 'cancel' at any time to quit.".colorize(:green)
46
+ puts "All fields are optional; simply press enter to skip a field.".colorize(:green)
47
+ puts "--------------------------------\n".colorize(:green)
48
+
49
+ title = get_user_input('Enter post title: ')
50
+ cancel_operation if title.downcase == 'cancel'
51
+
52
+ filename = if title.empty?
53
+ "#{Date.today.strftime('%Y-%m-%d')}.md"
54
+ else
55
+ "#{Date.today.strftime('%Y-%m-%d')}-#{title.downcase.gsub(' ', '-')}.md"
56
+ end
57
+
58
+ if File.exist?(filename)
59
+ puts "The file #{filename} already exists.".colorize(:red)
60
+ action = get_user_input("Choose an action: 'overwrite', 'rename', or 'cancel': ")
61
+
62
+ case action.downcase
63
+ when 'overwrite'
64
+ puts "Overwriting the existing file..."
65
+ when 'rename'
66
+ timestamp = Time.now.strftime('%Y-%m-%d-%H-%M-%S')
67
+ filename = "#{filename.gsub('.md', '')}-#{timestamp}.md"
68
+ puts "File renamed to #{filename}."
69
+ when 'cancel'
70
+ cancel_operation
71
+ else
72
+ puts "Invalid action. Cancelling operation..."
73
+ cancel_operation
74
+ end
75
+ end
76
+
77
+ description = get_user_input('Enter description: ')
78
+ cancel_operation if description.downcase == 'cancel'
79
+
80
+ tags = get_tags_from_user()
81
+ cancel_operation if tags.include?('cancel')
82
+
83
+ frontmatter = generate_frontmatter(title, description, tags)
84
+
85
+ File.open(filename, 'w') do |file|
86
+ file.puts "+++\n"
87
+ file.puts frontmatter
88
+ file.puts "+++\n"
89
+ end
90
+
91
+ puts "Frontmatter generated and saved to #{filename}.".colorize(:yellow)
data/sig/zolaposta.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Zolaposta
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/zolaposta.gemspec ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/zolaposta/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "zolaposta"
7
+ spec.version = '0.1.1'
8
+ spec.authors = ["nullpotential"]
9
+ spec.email = ["nupo@08182838.xyz"]
10
+
11
+ spec.summary = "A frontmatter generator for Zola blog posts."
12
+ spec.description = "This gem provides a command-line interface to generate frontmatter for Zola blog posts. Zola is a static site generator build with rust."
13
+ spec.homepage = "https://codeberg.org/nullpotential/zolaposta"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://codeberg.org/nullpotential/zolaposta"
21
+ spec.metadata["changelog_uri"] = "https://codeberg.org/nullpotential/zolaposta"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) ||
28
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
29
+ end
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ # Uncomment to register a new dependency of your gem
36
+ # spec.add_dependency "example-gem", "~> 1.0"
37
+ spec.add_dependency 'toml-rb'
38
+ spec.add_dependency 'date'
39
+ spec.add_dependency 'colorize'
40
+ spec.add_runtime_dependency 'thor'
41
+
42
+ # For more information and examples about making a new gem, check out our
43
+ # guide at: https://bundler.io/guides/creating_gem.html
44
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zolaposta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - nullpotential
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: toml-rb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: date
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: This gem provides a command-line interface to generate frontmatter for
70
+ Zola blog posts. Zola is a static site generator build with rust.
71
+ email:
72
+ - nupo@08182838.xyz
73
+ executables:
74
+ - zolaposta
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - exe/zolaposta
82
+ - lib/zolaposta.rb
83
+ - lib/zolaposta/version.rb
84
+ - sig/zolaposta.rbs
85
+ - zolaposta.gemspec
86
+ homepage: https://codeberg.org/nullpotential/zolaposta
87
+ licenses:
88
+ - MIT
89
+ metadata:
90
+ allowed_push_host: https://rubygems.org
91
+ homepage_uri: https://codeberg.org/nullpotential/zolaposta
92
+ source_code_uri: https://codeberg.org/nullpotential/zolaposta
93
+ changelog_uri: https://codeberg.org/nullpotential/zolaposta
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.6.0
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubygems_version: 3.4.22
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: A frontmatter generator for Zola blog posts.
113
+ test_files: []