jekyll-chatgpt 0.1.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/lib/chatgpt.sass +65 -59
- data/lib/chatgpt_message_label.js +10 -0
- data/lib/jekyll-chatgpt/version.rb +1 -1
- data/lib/jekyll-chatgpt.rb +61 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 681dec7900a693bd5210549c18140bf1d993059effb4ad8bfdf474995479bafb
|
4
|
+
data.tar.gz: e84ff1e7a0c1a5d40f62660b3a4a6188d6c47d269db3f3c94a9b92b1d68e0942
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 454e7a3ea814cf55314315c8ccf750e7cc54eb3ef6f04b315025683e32d27079a41b9fa7df7b2f158c611716791f2927f645c88929f940945826d4ea0dc1c164
|
7
|
+
data.tar.gz: 608139a4c8b3874c7d2f59b86905a2c97fafda1b602d2e62f645bf256016cd08d4c8f573d9509ba8894b4e88291a0ec50754ebdb48e94c500f4a933865ac53f9
|
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
|
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,11 +26,16 @@ 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
|
|
32
33
|
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`
|
33
34
|
|
35
|
+
### Customizing the SASS/CSS
|
36
|
+
|
37
|
+
You can put your custom SASS inside `_sass/_chatgpt_custom.sass`. If the file exists, it will be imported and the properties set in your custom stylesheet will take precedence by using [CSS layers](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer). The demo uses this to add rounded borders to the controls.
|
38
|
+
|
34
39
|
### Live demo
|
35
40
|
|
36
41
|
You can browse the [code for the live demo](https://github.com/pcouy/jekyll-chatgpt/tree/demo) which is intended to be a minimal example of using the plugin.
|
data/lib/chatgpt.sass
CHANGED
@@ -4,67 +4,73 @@ $color2: #cc3 !default
|
|
4
4
|
$color2-alt: #c3c !default
|
5
5
|
$cyan: #2aa198 !default
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
@layer chatgpt-default
|
8
|
+
.chatgpt-conversation
|
9
|
+
$tab-border: $color1-alt
|
10
|
+
position: relative
|
11
|
+
height: 400px
|
12
|
+
overflow-y: scroll
|
13
|
+
border: 1px solid $tab-border
|
14
|
+
margin: 2em 0.5em
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
16
|
+
.chatgpt-message
|
17
|
+
display: none
|
18
|
+
position: absolute
|
19
|
+
left: 0
|
20
|
+
width: 100%
|
21
|
+
top: 1.5em
|
22
|
+
&:target
|
23
|
+
border: 1px solid $color1
|
24
|
+
border-radius: 5px
|
25
|
+
width: 98%
|
26
|
+
margin: 0.75%
|
27
|
+
.chatgpt-control:checked ~ .chatgpt-message
|
28
|
+
display: block
|
29
|
+
&>.chatgpt-messagebody
|
30
|
+
margin-bottom: 0.5em
|
31
|
+
&>pre
|
32
|
+
display: inline
|
33
|
+
word-wrap: normal
|
34
|
+
white-space: pre-wrap
|
35
|
+
&>p
|
36
|
+
margin-block-start: 0.25em
|
37
|
+
margin-top: 0.25em
|
38
|
+
&>.chatgpt-message
|
39
|
+
display: block
|
40
|
+
top: 3em
|
35
41
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
.chatgpt-role-user::before
|
43
|
+
content: "User : "
|
44
|
+
color: $color2-alt
|
45
|
+
/*border: 1px solid $color1-alt
|
46
|
+
.chatgpt-role-assistant::before
|
47
|
+
content: "ChatGPT : "
|
48
|
+
color: $color2
|
49
|
+
/*border: 1px solid $color2
|
44
50
|
|
45
|
-
|
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
|
51
|
+
.chatgpt-messagechild
|
56
52
|
position: relative
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
53
|
+
.chatgpt-control
|
54
|
+
position: absolute
|
55
|
+
left: -300vw
|
56
|
+
&:only-child
|
57
|
+
& > label
|
58
|
+
display: none
|
59
|
+
& > .chatgpt-message
|
60
|
+
top: 0
|
61
|
+
& > label
|
62
|
+
position: relative
|
63
|
+
display: block
|
64
|
+
float: left
|
65
|
+
padding-right: 0.2em
|
66
|
+
padding-left: 0.2em
|
67
|
+
margin-top: 0.1em
|
68
|
+
&:first-child
|
69
|
+
margin-left: 0.3em
|
70
|
+
border-bottom: 1px solid $tab-border
|
71
|
+
.chatgpt-messagechild:first-child > label
|
63
72
|
margin-left: 0.3em
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
color: $cyan
|
69
|
-
border: 1px solid $tab-border
|
70
|
-
border-bottom: none
|
73
|
+
.chatgpt-control:checked + label
|
74
|
+
color: $cyan
|
75
|
+
border: 1px solid $tab-border
|
76
|
+
border-bottom: none
|
@@ -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
|
+
});
|
data/lib/jekyll-chatgpt.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require_relative "jekyll-chatgpt/version"
|
4
4
|
require "liquid"
|
5
|
+
require "jekyll"
|
6
|
+
require "jekyll/converters/scss"
|
5
7
|
|
6
8
|
module JekyllChatgpt
|
7
9
|
class Error < StandardError; end
|
@@ -24,24 +26,77 @@ module JekyllChatgpt
|
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
|
-
# Renders
|
29
|
+
# Renders nested `label` tags to display a message deep inside a branching
|
30
|
+
# conversation
|
31
|
+
class MessageLabel < Liquid::For
|
32
|
+
def render(context)
|
33
|
+
message_id_short = @variable_name
|
34
|
+
conversation = context.evaluate(@collection_name)
|
35
|
+
messages = conversation["mapping"]
|
36
|
+
message_id = messages.keys.filter do |id_candidate|
|
37
|
+
id_candidate.start_with? message_id_short
|
38
|
+
end.first
|
39
|
+
message_path = [message_id]
|
40
|
+
message = messages[message_id]
|
41
|
+
while message
|
42
|
+
message = messages[message["parent"]]
|
43
|
+
message_path.append(message["id"]) if message
|
44
|
+
end
|
45
|
+
res = "<a class=\"chatgpt-target\" href=\"\##{message_id}\">"
|
46
|
+
res += message_path.map do |path_id|
|
47
|
+
"<label class=\"chatgpt-deep-label\" for=\"chatgpt-control-#{path_id}\">"
|
48
|
+
end.join("")
|
49
|
+
res += @for_block.render(context)
|
50
|
+
res += message_path.map { |_| "</label>" }.join("")
|
51
|
+
res += "</a>"
|
52
|
+
res
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Renders needed styles and JS
|
28
57
|
class StyleGenerator < Jekyll::Generator
|
29
58
|
safe true
|
30
|
-
priority :
|
59
|
+
priority :highest
|
60
|
+
|
61
|
+
def sass_converter(site)
|
62
|
+
@sass_converter ||= Jekyll::Converters::Sass.new(site.config)
|
63
|
+
end
|
64
|
+
|
65
|
+
def sass_exists(site, file)
|
66
|
+
sass_converter(site).sass_load_paths.each do |dir|
|
67
|
+
return true unless Dir.new(dir).children.index(file).nil?
|
68
|
+
end
|
69
|
+
false
|
70
|
+
end
|
71
|
+
|
72
|
+
def colors_exists?(site)
|
73
|
+
sass_exists(site, "_colors.sass")
|
74
|
+
end
|
75
|
+
|
76
|
+
def style_exists?(site)
|
77
|
+
sass_exists(site, "_chatgpt_custom.sass")
|
78
|
+
end
|
79
|
+
|
80
|
+
def add_js(site)
|
81
|
+
message_label_js = Jekyll::StaticFile.new(site, __dir__, "", "chatgpt_message_label.js")
|
82
|
+
site.static_files << message_label_js
|
83
|
+
end
|
31
84
|
|
32
85
|
def generate(site)
|
33
86
|
chatgpt_style = Jekyll::PageWithoutAFile.new(site, __dir__, "", "chatgpt.sass")
|
34
87
|
chatgpt_style.tap do |file|
|
35
|
-
colors_exists = site.pages.filter do |page|
|
36
|
-
page.name =~ /colors\.sass$/i
|
37
|
-
end.size
|
38
88
|
file.content = ""
|
39
|
-
file.content += "@import \"colors\"\n" if colors_exists
|
89
|
+
file.content += "@import \"colors\"\n\n" if colors_exists?(site)
|
90
|
+
file.content += "@layer chatgpt-default, chatgpt-custom\n\n"
|
91
|
+
file.content += "@layer chatgpt-custom\n @import \"chatgpt_custom\"\n\n" if style_exists?(site)
|
40
92
|
file.content += File.read(File.expand_path("chatgpt.sass", __dir__))
|
41
93
|
end
|
42
94
|
site.pages << chatgpt_style
|
95
|
+
|
96
|
+
add_js(site)
|
43
97
|
end
|
44
98
|
end
|
45
99
|
end
|
46
100
|
|
47
101
|
Liquid::Template.register_filter(JekyllChatgpt::Filter)
|
102
|
+
Liquid::Template.register_tag("chatgpt_message_label", JekyllChatgpt::MessageLabel)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-chatgpt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pcouy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -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
|