jekyll-chatgpt 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9745e6b96766af9f9ee820f1bbddaae749abec521f6a9dee44852d888aacad99
4
- data.tar.gz: 9fbbb02a9740f94c67a6b11843c0e969854fc39cb9031d33a8820f22a626dbf4
3
+ metadata.gz: 4897cd9cf94d69f8d4ce0416eba0bf76b685dabccca22e9e2c15f6c33920d074
4
+ data.tar.gz: a6af3a6b8cbadba800968c8157557c310bf97736b0bfe48601277ba71cae2e8c
5
5
  SHA512:
6
- metadata.gz: fb4e6b1b27a65d87c391712ee8041295a7a1aec2e4640d26f0fbc2880b346e18aabfddcb331090fc5f62bbe83088fa0fe9bb2eb149c14f4635f8e0c0654d6375
7
- data.tar.gz: 53f4394e44e94aed87abb411ca706c8a50167a16071e5308cb9ce6c46fcb62d9a931bd44fbe925eb678cd1ef835c254542d5b624e9fd501c271634291e7ca909
6
+ metadata.gz: 58d614fee1d9bb4c82286a8b787a0224ae94da8101ffd084d579c2b1808e5875fa192c1cc2d481fb8687d85bb070006730d60643c0b3d2239189d23282fcae06
7
+ data.tar.gz: 968d297f492fc523b6e8c28547e42cf7f63cdfc504aabacd1b873b0352f8f4d434f118a096d67e191643c1b2bbd92bf8bcefae31dc8db38db880beeadf904c07
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # JekyllChatgpt
2
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) ([code](https://github.com/pcouy/jekyll-chatgpt/tree/demo))
3
+ This plugin inctroduces a `chatgpt` Liquid filter that formats ChatGPT conversations. It mostly uses CSS to navigate in branching conversations (except for links to specific messages inside a conversation, see "Usage" below). A [live demo of deploying the demo branch of this repository to Github pages is available](https://pierre-couy.dev/jekyll-chatgpt) ([code](https://github.com/pcouy/jekyll-chatgpt/tree/demo))
4
4
 
5
5
  ## Installation
6
6
 
@@ -26,6 +26,7 @@ Optionally, include a stylesheet for code syntax highlighting in ChatGPT output.
26
26
 
27
27
  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`).
28
28
  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 }}`.
29
+ 3. You will be able to link to specific messages in conversations by using the `chatgpt_message_lagel` tag in the following way : `{% chatgpt_message_label [MESSAGE_ID] in [CONVERSATION] %}[LABEL_TEXT]{% endchatgpt_message_label %}` where `[MESSAGE_ID]` is the start of a message id ; `[CONVERSATION]` is the variable representing a conversation ; `[LABEL_TEXT]` is the displayed link text. Here is an example from [the demo page](https://pierre-couy.dev/jekyll-chatgpt) : `{% chatgpt_message_label 55bb5 in site.data.chatgpt["date"] %}a message{% endchatgpt_message_label %}`. This functionality uses Javascript, if you want to use it you must add the following tag to your `<head>` : `<script defer src="/chatgpt_message_label.js"></script>` (the JS file is automatically written to your website's output directory)
29
30
 
30
31
  ### Customizing the colors
31
32
 
data/lib/chatgpt.sass CHANGED
@@ -18,6 +18,11 @@ $cyan: #2aa198 !default
18
18
  left: 0
19
19
  width: 100%
20
20
  top: 1.5em
21
+ &:target
22
+ border: 1px solid $color1
23
+ border-radius: 5px
24
+ width: 98%
25
+ margin: 0.75%
21
26
  .chatgpt-control:checked ~ .chatgpt-message
22
27
  display: block
23
28
  &>.chatgpt-messagebody
@@ -0,0 +1,10 @@
1
+ document.querySelectorAll('.chatgpt-deep-label').forEach(e=>{
2
+ e.addEventListener("click",ev=>{
3
+ ev.preventDefault();
4
+ t=document.querySelector(`.chatgpt-control + label[for=${e.attributes["for"].value}]`);
5
+ if(t) t.click();
6
+ if(e.parentElement.classList.contains("chatgpt-target")) {
7
+ e.parentElement.click();
8
+ }
9
+ })
10
+ });
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllChatgpt
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "jekyll-chatgpt/version"
4
4
  require "liquid"
5
+ require "jekyll"
5
6
 
6
7
  module JekyllChatgpt
7
8
  class Error < StandardError; end
@@ -24,7 +25,34 @@ module JekyllChatgpt
24
25
  end
25
26
  end
26
27
 
27
- # Renders chatgpt.sass to /chatgpt.css
28
+ # Renders nested `label` tags to display a message deep inside a branching
29
+ # conversation
30
+ class MessageLabel < Liquid::For
31
+ def render(context)
32
+ message_id_short = @variable_name
33
+ conversation = context.evaluate(@collection_name)
34
+ messages = conversation["mapping"]
35
+ message_id = messages.keys.filter do |id_candidate|
36
+ id_candidate.start_with? message_id_short
37
+ end.first
38
+ message_path = [message_id]
39
+ message = messages[message_id]
40
+ while message
41
+ message = messages[message["parent"]]
42
+ message_path.append(message["id"]) if message
43
+ end
44
+ res = "<a class=\"chatgpt-target\" href=\"\##{message_id}\">"
45
+ res += message_path.map do |path_id|
46
+ "<label class=\"chatgpt-deep-label\" for=\"chatgpt-control-#{path_id}\">"
47
+ end.join("")
48
+ res += @for_block.render(context)
49
+ res += message_path.map { |_| "</label>" }.join("")
50
+ res += "</a>"
51
+ res
52
+ end
53
+ end
54
+
55
+ # Renders needed styles and JS
28
56
  class StyleGenerator < Jekyll::Generator
29
57
  safe true
30
58
  priority :lowest
@@ -40,8 +68,12 @@ module JekyllChatgpt
40
68
  file.content += File.read(File.expand_path("chatgpt.sass", __dir__))
41
69
  end
42
70
  site.pages << chatgpt_style
71
+
72
+ message_label_js = Jekyll::StaticFile.new(site, __dir__, "", "chatgpt_message_label.js")
73
+ site.static_files << message_label_js
43
74
  end
44
75
  end
45
76
  end
46
77
 
47
78
  Liquid::Template.register_filter(JekyllChatgpt::Filter)
79
+ Liquid::Template.register_tag("chatgpt_message_label", JekyllChatgpt::MessageLabel)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-chatgpt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pcouy
@@ -41,6 +41,7 @@ files:
41
41
  - lib/chatgpt.sass
42
42
  - lib/chatgpt_innermessage.html
43
43
  - lib/chatgpt_message.html
44
+ - lib/chatgpt_message_label.js
44
45
  - lib/jekyll-chatgpt.rb
45
46
  - lib/jekyll-chatgpt/version.rb
46
47
  - sig/jekyll_chatgpt.rbs