jekyll-chatgpt 0.1.0

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: bb1b5f419fe7df8334c5248d953838081ac4c8237a202b259c2f4fb2267878f1
4
+ data.tar.gz: 12271c751c986329d8e8590c52cadcee09f6e565f517101ba7ce9295ba77d92f
5
+ SHA512:
6
+ metadata.gz: 3d06af997f0486c935098393a264e2e3511374a73bcf9a655bb429ea78264b47eed601a6a5909f1fc59716c1e39b2b786ee68a465f5b850a8a5a23a05e89cec9
7
+ data.tar.gz: 0601fc5c41c7da82658c2f40376fee4388664c9c326e506fbef93cf2cc53a0bcd21129fdeb0a5e498cc5c6a111f023644e0fe966954b488f3aa34d69c23248ce
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/MethodLength:
16
+ Enabled: false
17
+
18
+ Metrics/AbcSize:
19
+ Enabled: false
20
+
21
+ Naming/MethodParameterName:
22
+ Enabled: false
23
+
24
+ Naming/FileName:
25
+ Enabled: false
26
+
27
+ Stylez/OptionalBooleanParameter:
28
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in jekyll_chatgpt.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.21"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 pcouy
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,40 @@
1
+ # JekyllChatgpt
2
+
3
+ This plugin inctroduces a `chatgpt` Liquid filter that formats ChatGPT conversations. It only uses CSS to navigate in branching conversations. A [live demo of deploying the demo branch of this repository to Github pages is available](https://pierre-couy.dev/jekyll-chatgpt)
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add jekyll-chatgpt
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install jekyll-chatgpt
14
+
15
+ Optionally, include a stylesheet for code syntax highlighting in ChatGPT output. If you already have a code highlighting theme set up for your site, it should automatically be used.
16
+
17
+ ## Usage
18
+
19
+ ### Including a conversation
20
+
21
+ 1. Download a conversation from [your ChatGPT history](https://chat.openai.com/). When on the ChatGPT web page, open your browser dev-tools (usually using F12) and go to the "Network" tab. Now, pick a conversation in the web-app. The URL in your browser should now look like `chat.openapi.com/chat/{some-random-looking-id}`. In the network tab of the developer tools, find the request to `{some-random-looking-id}` and right-click on it and pick "Copy > Copy response". You can now paste what you just copied into a JSON file inside your `_data` folder (for instance, `_data/chatgpt/test_conversation.json`).
22
+ 2. You can now use `{{ site.data.chatgpt['test_conversation'] | chatgpt }}` anywhere in your liquid-rendered content to include the conversation in your website. This will render markdown in messages by default. You can disable markdown rendering by passing the `false` argument to the filter : `{{ site.data.chatgpt['test_conversation'] | chatgpt: false }}`.
23
+
24
+ ### Customizing the colors
25
+
26
+ The necessary styles will automatically be inlined when using the filter. You can override the default colors by providing the following variables in your `_sass/_colors.sass` file : `$color1`, `$color1-alt`, `$color2`, `$color2-alt`, `$cyan`
27
+
28
+ ## Development
29
+
30
+ 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.
31
+
32
+ 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).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jekyll_chatgpt.
37
+
38
+ ## License
39
+
40
+ 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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/lib/chatgpt.html ADDED
@@ -0,0 +1,10 @@
1
+ {% unless chatgpt_style_included %}
2
+ <link rel="stylesheet" type="text/css" href="{{ 'chatgpt.css' | relative_url }}">
3
+ {% assign chatgpt_style_included = true %}
4
+ {% endunless %}
5
+ <section class="chatgpt-conversation">
6
+ <h1>{{ conversation.title }}</h1>
7
+ {% assign message=conversation.mapping | find_exp:"item", "item.parent == nil" %}
8
+ {% assign messages=conversation.mapping | where_exp:"item", "item.parent == nil" %}
9
+ {% include chatgpt_message.html %}
10
+ </section>
data/lib/chatgpt.sass ADDED
@@ -0,0 +1,70 @@
1
+ $color1: #fff !default
2
+ $color1-alt: #aaa !default
3
+ $color2: #cc3 !default
4
+ $color2-alt: #c3c !default
5
+ $cyan: #2aa198 !default
6
+
7
+ .chatgpt-conversation
8
+ $tab-border: $color1-alt
9
+ position: relative
10
+ height: 400px
11
+ overflow-y: scroll
12
+ border: 1px solid $tab-border
13
+ margin: 2em 0.5em
14
+
15
+ .chatgpt-message
16
+ display: none
17
+ position: absolute
18
+ left: 0
19
+ width: 100%
20
+ top: 1.5em
21
+ .chatgpt-control:checked ~ .chatgpt-message
22
+ display: block
23
+ &>.chatgpt-messagebody
24
+ margin-bottom: 0.5em
25
+ &>pre
26
+ display: inline
27
+ word-wrap: normal
28
+ white-space: pre-wrap
29
+ &>p
30
+ margin-block-start: 0.25em
31
+ margin-top: 0.25em
32
+ &>.chatgpt-message
33
+ display: block
34
+ top: 3em
35
+
36
+ .chatgpt-role-user::before
37
+ content: "User : "
38
+ color: $color2-alt
39
+ /*border: 1px solid $color1-alt
40
+ .chatgpt-role-assistant::before
41
+ content: "ChatGPT : "
42
+ color: $color2
43
+ /*border: 1px solid $color2
44
+
45
+ .chatgpt-messagechild
46
+ position: relative
47
+ .chatgpt-control
48
+ position: absolute
49
+ left: -300vw
50
+ &:only-child
51
+ & > label
52
+ display: none
53
+ & > .chatgpt-message
54
+ top: 0
55
+ & > label
56
+ position: relative
57
+ display: block
58
+ float: left
59
+ padding-right: 0.2em
60
+ padding-left: 0.2em
61
+ margin-top: 0.1em
62
+ &:first-child
63
+ margin-left: 0.3em
64
+ border-bottom: 1px solid $tab-border
65
+ .chatgpt-messagechild:first-child > label
66
+ margin-left: 0.3em
67
+ .chatgpt-control:checked + label
68
+ color: $cyan
69
+ border: 1px solid $tab-border
70
+ border-bottom: none
@@ -0,0 +1,32 @@
1
+ {% assign outer_message=messages | last %}
2
+ <div class="chatgpt-message" id="{{outer_message.id}}">
3
+ {% if outer_message.message %}
4
+ <div class="chatgpt-messagebody chatgpt-role-{{ outer_message.message.author.role }}">
5
+ {% if mdfy %}
6
+ {{ outer_message.message.content.parts[0] | markdownify }}
7
+ {% else %}
8
+ <pre>{{ outer_message.message.content.parts[0] }}</pre>
9
+ {% endif %}
10
+ </div>
11
+ {% endif %}
12
+ <div class="chatgpt-messagechildren">
13
+ {% for child_id in outer_message.children %}
14
+ <!-- D {% increment depth %} -->
15
+ {% assign inner_message=conversation.mapping[child_id] %}
16
+ {% assign messages = messages | push: inner_message %}
17
+ <div class="chatgpt-messagechild">
18
+ <input type="radio"
19
+ name="chatgpt-{{ outer_message.id }}"
20
+ id="chatgpt-control-{{ inner_message.id }}"
21
+ class="chatgpt-control"
22
+ {% if forloop.first %}checked{% endif %}
23
+ >
24
+ <label for="chatgpt-control-{{ inner_message.id }}">{{ forloop.index }}</label>
25
+ {% include chatgpt_message.html %}
26
+ </div>
27
+ {% assign messages = messages | slice: 0, depth %}
28
+ {% assign outer_message=messages.last %}
29
+ <!-- D {% decrement depth %} -->
30
+ {% endfor %}
31
+ </div>
32
+ </div>
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllChatgpt
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "jekyll-chatgpt/version"
4
+ require "liquid"
5
+
6
+ module JekyllChatgpt
7
+ class Error < StandardError; end
8
+
9
+ # Filter to transform ChatGPT data into HTML/CSS viewer
10
+ module Filter
11
+ def chatgpt(input, markdownify = true)
12
+ site = @context.registers[:site]
13
+ @context["conversation"] = input
14
+ @context["mdfy"] = markdownify
15
+
16
+ inclusion = site.liquid_renderer.file("chatgpt.html")
17
+ inclusion.parse(File.read(File.expand_path("chatgpt.html", __dir__)))
18
+
19
+ site.includes_load_paths.push(__dir__)
20
+ res = inclusion.render(@context)
21
+ site.includes_load_paths.pop
22
+
23
+ res
24
+ end
25
+ end
26
+
27
+ # Renders chatgpt.sass to /chatgpt.css
28
+ class StyleGenerator < Jekyll::Generator
29
+ safe true
30
+ priority :lowest
31
+
32
+ def generate(site)
33
+ chatgpt_style = Jekyll::PageWithoutAFile.new(site, __dir__, "", "chatgpt.sass")
34
+ chatgpt_style.tap do |file|
35
+ colors_exists = site.pages.filter do |page|
36
+ page.name =~ /colors\.sass$/i
37
+ end.size
38
+ file.content = ""
39
+ file.content += "@import \"colors\"\n" if colors_exists
40
+ file.content += File.read(File.expand_path("chatgpt.sass", __dir__))
41
+ end
42
+ site.pages << chatgpt_style
43
+ end
44
+ end
45
+ end
46
+
47
+ Liquid::Template.register_filter(JekyllChatgpt::Filter)
@@ -0,0 +1,4 @@
1
+ module JekyllChatgpt
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-chatgpt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - pcouy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-04-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Use OpenAI API JSON as data files and display branching conversations
14
+ on your website
15
+ email:
16
+ - contact@pierre-couy.dev
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rubocop.yml"
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/chatgpt.html
27
+ - lib/chatgpt.sass
28
+ - lib/chatgpt_message.html
29
+ - lib/jekyll-chatgpt.rb
30
+ - lib/jekyll-chatgpt/version.rb
31
+ - sig/jekyll_chatgpt.rbs
32
+ homepage: https://github.com/pcouy/jekyll-chatgpt
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ allowed_push_host: https://rubygems.org
37
+ homepage_uri: https://github.com/pcouy/jekyll-chatgpt
38
+ source_code_uri: https://github.com/pcouy/jekyll-chatgpt
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.6.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.3.25
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Display and navigate branching ChatGPT conversations
58
+ test_files: []