notes-to-strapi-export-article-ai 1.0.11 → 1.0.13

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.
@@ -0,0 +1,418 @@
1
+ import { App, Notice, PluginSettingTab, Setting } from 'obsidian'
2
+ import StrapiExporterPlugin from './main'
3
+ import { validateJsonTemplate } from './utils/validators'
4
+
5
+ export class StrapiExporterSettingTab extends PluginSettingTab {
6
+ plugin: StrapiExporterPlugin
7
+
8
+ constructor(app: App, plugin: StrapiExporterPlugin) {
9
+ super(app, plugin)
10
+ this.plugin = plugin
11
+ }
12
+
13
+ display(): void {
14
+ // Display settings fields
15
+ const { containerEl } = this
16
+ containerEl.empty()
17
+
18
+ /** ****************************************************************************
19
+ * Add the settings for the plugin
20
+ * *****************************************************************************
21
+ */
22
+ containerEl.createEl('h1', { text: 'Strapi & OpenAI Settings' })
23
+ new Setting(containerEl)
24
+ .setName('Strapi API Token')
25
+ .setDesc('Enter your Strapi API token')
26
+ .addText(text =>
27
+ text
28
+ .setPlaceholder('Enter your token')
29
+ .setValue(this.plugin.settings.strapiApiToken)
30
+ .onChange(async value => {
31
+ this.plugin.settings.strapiApiToken = value
32
+ await this.plugin.saveSettings()
33
+ })
34
+ )
35
+
36
+ new Setting(containerEl)
37
+ .setName('OpenAI API Key')
38
+ .setDesc('Enter your OpenAI API key for GPT-3')
39
+ .addText(text =>
40
+ text
41
+ .setPlaceholder('Enter your OpenAI API key')
42
+ .setValue(this.plugin.settings.openaiApiKey)
43
+ .onChange(async value => {
44
+ this.plugin.settings.openaiApiKey = value
45
+ await this.plugin.saveSettings()
46
+ })
47
+ )
48
+
49
+ new Setting(containerEl)
50
+ .setName('Additional Prompt')
51
+ .setDesc(
52
+ 'Enter an optional additional prompt to customize the article content generation'
53
+ )
54
+ .addTextArea(text =>
55
+ text
56
+ .setPlaceholder('Enter your additional prompt here...')
57
+ .setValue(this.plugin.settings.additionalPrompt)
58
+ .onChange(async value => {
59
+ this.plugin.settings.additionalPrompt = value
60
+ await this.plugin.saveSettings()
61
+ })
62
+ )
63
+
64
+ containerEl.createEl('h1', { text: 'Strapi Settings - Call 1' })
65
+
66
+ new Setting(containerEl)
67
+ .setName('Strapi URL')
68
+ .setDesc('Enter your Strapi instance URL')
69
+ .addText(text =>
70
+ text
71
+ .setPlaceholder('https://your-strapi-url')
72
+ .setValue(this.plugin.settings.strapiUrl)
73
+ .onChange(async value => {
74
+ this.plugin.settings.strapiUrl = value
75
+ await this.plugin.saveSettings()
76
+ })
77
+ )
78
+
79
+ new Setting(containerEl)
80
+ .setName('JSON Template')
81
+ .setDesc('Enter the JSON template for the fields needed')
82
+ .addTextArea(text =>
83
+ text
84
+ .setPlaceholder('Enter your JSON template')
85
+ .setValue(this.plugin.settings.jsonTemplate)
86
+ .onChange(async value => {
87
+ if (validateJsonTemplate(value)) {
88
+ this.plugin.settings.jsonTemplate = value
89
+ await this.plugin.saveSettings()
90
+ new Notice('JSON template saved successfully. (valid !)')
91
+ } else {
92
+ new Notice(
93
+ 'Invalid JSON template. Please enter a valid JSON template.'
94
+ )
95
+ }
96
+ })
97
+ )
98
+
99
+ new Setting(containerEl)
100
+ .setName('JSON Template Description')
101
+ .setDesc('Enter the description for each field in the JSON template')
102
+ .addTextArea(text =>
103
+ text
104
+ .setPlaceholder('Enter the field descriptions')
105
+ .setValue(this.plugin.settings.jsonTemplateDescription)
106
+ .onChange(async value => {
107
+ this.plugin.settings.jsonTemplateDescription = value
108
+ await this.plugin.saveSettings()
109
+ })
110
+ )
111
+
112
+ new Setting(containerEl)
113
+ .setName('Strapi Article Create URL')
114
+ .setDesc('Enter the URL to create articles in Strapi')
115
+ .addText(text =>
116
+ text
117
+ .setPlaceholder('https://your-strapi-url/api/articles')
118
+ .setValue(this.plugin.settings.strapiArticleCreateUrl)
119
+ .onChange(async value => {
120
+ this.plugin.settings.strapiArticleCreateUrl = value
121
+ await this.plugin.saveSettings()
122
+ })
123
+ )
124
+
125
+ new Setting(containerEl)
126
+ .setName('Strapi Content Attribute Name')
127
+ .setDesc('Enter the attribute name for the content field in Strapi')
128
+ .addText(text =>
129
+ text
130
+ .setPlaceholder('content')
131
+ .setValue(this.plugin.settings.strapiContentAttributeName)
132
+ .onChange(async value => {
133
+ this.plugin.settings.strapiContentAttributeName = value
134
+ await this.plugin.saveSettings()
135
+ })
136
+ )
137
+
138
+ containerEl.createEl('h2', { text: 'Main Image Settings' })
139
+
140
+ new Setting(containerEl)
141
+ .setName('Enable Main Image')
142
+ .setDesc('Toggle the main image')
143
+ .addToggle(toggle =>
144
+ toggle
145
+ .setValue(this.plugin.settings.mainButtonImageEnabled)
146
+ .onChange(async value => {
147
+ this.plugin.settings.mainButtonImageEnabled = value
148
+ await this.plugin.saveSettings()
149
+ this.display()
150
+ })
151
+ )
152
+
153
+ if (this.plugin.settings.mainButtonImageEnabled) {
154
+ // Display main image settings
155
+ containerEl.createEl('p', {
156
+ text: 'For the plugin to detect images and galleries, ensure the following folder structure:',
157
+ })
158
+
159
+ containerEl.createEl('ul', {
160
+ text: '- Article file (e.g., article.md)',
161
+ })
162
+ containerEl.createEl('ul', {
163
+ text: '- Main image folder (name: image)',
164
+ })
165
+
166
+ containerEl.createEl('p', {
167
+ text: 'The plugin will detect images in the main image (for this api call)',
168
+ })
169
+
170
+ new Setting(containerEl)
171
+ .setName('Main Image Full Path Property')
172
+ .setDesc(
173
+ 'Enter the full path property for the main image in the final call'
174
+ )
175
+ .addText(text =>
176
+ text
177
+ .setPlaceholder('data.attributes.image')
178
+ .setValue(this.plugin.settings.mainImageFullPathProperty)
179
+ .onChange(async value => {
180
+ this.plugin.settings.mainImageFullPathProperty = value
181
+ await this.plugin.saveSettings()
182
+ })
183
+ )
184
+ }
185
+
186
+ containerEl.createEl('h2', { text: 'Main Gallery Settings' })
187
+
188
+ new Setting(containerEl)
189
+ .setName('Enable Main Gallery')
190
+ .setDesc('Toggle the main gallery')
191
+ .addToggle(toggle =>
192
+ toggle
193
+ .setValue(this.plugin.settings.mainButtonGalleryEnabled)
194
+ .onChange(async value => {
195
+ this.plugin.settings.mainButtonGalleryEnabled = value
196
+ await this.plugin.saveSettings()
197
+ this.display()
198
+ })
199
+ )
200
+
201
+ if (this.plugin.settings.mainButtonGalleryEnabled) {
202
+ containerEl.createEl('p', {
203
+ text: 'For the plugin to detect galleries, ensure the following folder structure:',
204
+ })
205
+
206
+ containerEl.createEl('ul', {
207
+ text: '- Article file (e.g., article.md)',
208
+ })
209
+ containerEl.createEl('ul', {
210
+ text: '- Main gallery folder (name: gallery)',
211
+ })
212
+
213
+ containerEl.createEl('p', {
214
+ text: 'The plugin will detect images in the main gallery folders. (for this api call)',
215
+ })
216
+
217
+ new Setting(containerEl)
218
+ .setName('Main Gallery Full Path Property')
219
+ .setDesc(
220
+ 'Enter the full path property for the main gallery in the final call'
221
+ )
222
+ .addText(text =>
223
+ text
224
+ .setPlaceholder('data.attributes.gallery')
225
+ .setValue(this.plugin.settings.mainGalleryFullPathProperty)
226
+ .onChange(async value => {
227
+ this.plugin.settings.mainGalleryFullPathProperty = value
228
+ await this.plugin.saveSettings()
229
+ })
230
+ )
231
+ }
232
+
233
+ containerEl.createEl('h1', {
234
+ text: 'Strapi Settings - Call 2 - Additional call',
235
+ })
236
+ containerEl.createEl('p', {
237
+ text: `(Be careful, when enabling this feature, you'll need to restart Obsidian to see the additional button in the ribbon menu.)`,
238
+ })
239
+
240
+ new Setting(containerEl)
241
+ .setName('Enable Additional Call API')
242
+ .setDesc(
243
+ 'Toggle the additional Call API, and display a new icon in the ribbon menu'
244
+ )
245
+ .addToggle(toggle =>
246
+ toggle
247
+ .setValue(this.plugin.settings.enableAdditionalApiCall)
248
+ .onChange(async value => {
249
+ this.plugin.settings.enableAdditionalApiCall = value
250
+ await this.plugin.saveSettings()
251
+ this.display()
252
+ })
253
+ )
254
+
255
+ if (this.plugin.settings.enableAdditionalApiCall) {
256
+ new Setting(containerEl)
257
+ .setName('Additional JSON Template')
258
+ .setDesc(
259
+ 'Enter the JSON template for the fields needed for the additional api'
260
+ )
261
+ .addTextArea(text =>
262
+ text
263
+ .setPlaceholder('Enter your JSON template')
264
+ .setValue(this.plugin.settings.additionalJsonTemplate)
265
+ .onChange(async value => {
266
+ if (validateJsonTemplate(value)) {
267
+ this.plugin.settings.additionalJsonTemplate = value
268
+ await this.plugin.saveSettings()
269
+ new Notice('JSON template saved successfully. (valid !)')
270
+ } else {
271
+ new Notice(
272
+ 'Invalid additional JSON template. Please enter a valid JSON template.'
273
+ )
274
+ }
275
+ })
276
+ )
277
+
278
+ new Setting(containerEl)
279
+ .setName('Additional API JSON Template Description')
280
+ .setDesc(
281
+ 'Enter the description for each field in the additional API JSON template'
282
+ )
283
+ .addTextArea(text =>
284
+ text
285
+ .setPlaceholder('Enter the field descriptions')
286
+ .setValue(this.plugin.settings.additionalJsonTemplateDescription)
287
+ .onChange(async value => {
288
+ this.plugin.settings.additionalJsonTemplateDescription = value
289
+ await this.plugin.saveSettings()
290
+ })
291
+ )
292
+
293
+ new Setting(containerEl)
294
+ .setName('Additional API URL')
295
+ .setDesc('Enter the URL to create content for the additional API')
296
+ .addText(text =>
297
+ text
298
+ .setPlaceholder('https://your-strapi-url/api/additional-content')
299
+ .setValue(this.plugin.settings.additionalUrl)
300
+ .onChange(async value => {
301
+ this.plugin.settings.additionalUrl = value
302
+ await this.plugin.saveSettings()
303
+ })
304
+ )
305
+
306
+ new Setting(containerEl)
307
+ .setName('Additional API Content Attribute Name')
308
+ .setDesc(
309
+ 'Enter the attribute name for the content field for the additional API'
310
+ )
311
+ .addText(text =>
312
+ text
313
+ .setPlaceholder('content')
314
+ .setValue(this.plugin.settings.additionalContentAttributeName)
315
+ .onChange(async value => {
316
+ this.plugin.settings.additionalContentAttributeName = value
317
+ await this.plugin.saveSettings()
318
+ })
319
+ )
320
+
321
+ containerEl.createEl('h2', { text: 'Additional Call api Image Settings' })
322
+
323
+ new Setting(containerEl)
324
+ .setName('Enable Additional Call API Image')
325
+ .setDesc('Toggle the additional Call API image')
326
+ .addToggle(toggle =>
327
+ toggle
328
+ .setValue(this.plugin.settings.additionalButtonImageEnabled)
329
+ .onChange(async value => {
330
+ this.plugin.settings.additionalButtonImageEnabled = value
331
+ await this.plugin.saveSettings()
332
+ this.display()
333
+ })
334
+ )
335
+
336
+ if (this.plugin.settings.additionalButtonImageEnabled) {
337
+ containerEl.createEl('p', {
338
+ text: 'For the plugin to detect images and galleries, ensure the following folder structure:',
339
+ })
340
+
341
+ containerEl.createEl('ul', {
342
+ text: '- Article file (e.g., article.md)',
343
+ })
344
+ containerEl.createEl('ul', {
345
+ text: '- Main image folder (name: image)',
346
+ })
347
+
348
+ containerEl.createEl('p', {
349
+ text: 'The plugin will detect images in the main image (for this api call)',
350
+ })
351
+
352
+ new Setting(containerEl)
353
+ .setName('Additional Call API Image Full Path Property')
354
+ .setDesc(
355
+ 'Enter the full path property for the additional Call API image in the final call'
356
+ )
357
+ .addText(text =>
358
+ text
359
+ .setPlaceholder('image_presentation')
360
+ .setValue(this.plugin.settings.additionalImageFullPathProperty)
361
+ .onChange(async value => {
362
+ this.plugin.settings.additionalImageFullPathProperty = value
363
+ await this.plugin.saveSettings()
364
+ })
365
+ )
366
+ }
367
+
368
+ containerEl.createEl('h2', {
369
+ text: 'Additional Call API Gallery Settings',
370
+ })
371
+
372
+ new Setting(containerEl)
373
+ .setName('Enable Additional Call API Gallery')
374
+ .setDesc('Toggle the additional Call API gallery')
375
+ .addToggle(toggle =>
376
+ toggle
377
+ .setValue(this.plugin.settings.additionalButtonGalleryEnabled)
378
+ .onChange(async value => {
379
+ this.plugin.settings.additionalButtonGalleryEnabled = value
380
+ await this.plugin.saveSettings()
381
+ this.display()
382
+ })
383
+ )
384
+
385
+ if (this.plugin.settings.additionalButtonGalleryEnabled) {
386
+ containerEl.createEl('p', {
387
+ text: 'For the plugin to detect galleries, ensure the following folder structure:',
388
+ })
389
+
390
+ containerEl.createEl('ul', {
391
+ text: '- Article file (e.g., article.md)',
392
+ })
393
+ containerEl.createEl('ul', {
394
+ text: '- Main gallery folder (name: gallery)',
395
+ })
396
+
397
+ containerEl.createEl('p', {
398
+ text: 'The plugin will detect images in the main gallery folders. (for this api call)',
399
+ })
400
+
401
+ new Setting(containerEl)
402
+ .setName('Additional Call API Gallery Full Path Property')
403
+ .setDesc(
404
+ 'Enter the full path property for the additional Call API gallery in the final call'
405
+ )
406
+ .addText(text =>
407
+ text
408
+ .setPlaceholder('galery')
409
+ .setValue(this.plugin.settings.additionalGalleryFullPathProperty)
410
+ .onChange(async value => {
411
+ this.plugin.settings.additionalGalleryFullPathProperty = value
412
+ await this.plugin.saveSettings()
413
+ })
414
+ )
415
+ }
416
+ }
417
+ }
418
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Article
3
+ */
4
+ export interface ArticleContent {
5
+ data: {
6
+ [key: string]: any
7
+ }
8
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Image types
3
+ */
4
+ export interface ImageBlob {
5
+ path: string
6
+ blob: Blob
7
+ name: string
8
+ id?: any
9
+ }
10
+
11
+ /**
12
+ * Image description
13
+ */
14
+ export interface ImageDescription extends ImageBlob {
15
+ description: {
16
+ name: string
17
+ alternativeText: string
18
+ caption: string
19
+ }
20
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The settings for the Strapi Exporter plugin
3
+ */
4
+ export interface StrapiExporterSettings {
5
+ strapiUrl: string
6
+ strapiApiToken: string
7
+ openaiApiKey: string
8
+ jsonTemplate: string
9
+ jsonTemplateDescription: string
10
+ strapiArticleCreateUrl: string
11
+ strapiContentAttributeName: string
12
+ additionalPrompt: string
13
+ enableAdditionalApiCall: boolean
14
+ additionalJsonTemplate: string
15
+ additionalJsonTemplateDescription: string
16
+ additionalUrl: string
17
+ additionalContentAttributeName: string
18
+ // enable elements
19
+ mainButtonImageEnabled: boolean
20
+ mainButtonGalleryEnabled: boolean
21
+ additionalButtonImageEnabled: boolean
22
+ additionalButtonGalleryEnabled: boolean
23
+ // images and galleries paths (for the body api call)
24
+ mainImageFullPathProperty: string
25
+ mainGalleryFullPathProperty: string
26
+ additionalImageFullPathProperty: string
27
+ additionalGalleryFullPathProperty: string
28
+ }