From 7ae2e6c7a776e4384be66b76036f7ae9e01c3188 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Tue, 2 Jul 2024 18:18:57 -0500 Subject: [PATCH 1/3] Commiting detached image. --- repository/TiddlyWiki/Tiddler.class.st | 15 ++++++++++++++- repository/TiddlyWiki/TiddlyWiki.class.st | 20 +++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/repository/TiddlyWiki/Tiddler.class.st b/repository/TiddlyWiki/Tiddler.class.st index a040b07..902297a 100644 --- a/repository/TiddlyWiki/Tiddler.class.st +++ b/repository/TiddlyWiki/Tiddler.class.st @@ -214,7 +214,10 @@ Tiddler >> exportSTONFile [ { #category : #accessing } Tiddler >> exportSTONFileInto: subfolder [ - | stonFile | + | stonFile tiddlersSubfolder | + tiddlersSubfolder := self wiki folder / subfolder. + tiddlersSubfolder exists + ifFalse: [ tiddlersSubfolder ensureCreateDirectory ]. stonFile := self wiki folder / subfolder / self fileName. ^ MarkupFile exportAsFileOn: stonFile containing: self asStonStringPretty ] @@ -537,6 +540,16 @@ Tiddler >> tagsAsString [ ^ response contents ] +{ #category : #accessing } +Tiddler >> tagsReformating [ + | response | + self tags class ~= ByteString ifTrue: [ ^ self ]. + response := Set new. + response add: self tags. + self tags: response. + +] + { #category : #accessing } Tiddler >> text [ diff --git a/repository/TiddlyWiki/TiddlyWiki.class.st b/repository/TiddlyWiki/TiddlyWiki.class.st index dd5be0c..7d77d8b 100644 --- a/repository/TiddlyWiki/TiddlyWiki.class.st +++ b/repository/TiddlyWiki/TiddlyWiki.class.st @@ -262,6 +262,10 @@ TiddlyWiki >> exportJSONFile [ ^ MarkupFile exportAsFileOn: self jsonFile containing: rawJsonTiddlers ] +{ #category : #accessing } +TiddlyWiki >> exportJSONFileFromTiddlers [ +] + { #category : #accessing } TiddlyWiki >> exportJSONFileOptimized [ @@ -493,6 +497,18 @@ TiddlyWiki >> importJSONLink [ ^ self fromString: self remoteTiddlersContentsString ] +{ #category : #accessing } +TiddlyWiki >> importSTONFilesFrom: aFolder [ + | tiddlerFiles | + self folder: aFolder parent. + tiddlerFiles := aFolder children + select: [ :localFile | localFile basename endsWith: '.ston' ]. + self tiddlers: (tiddlerFiles collect: [ :each | | tempTiddler| + tempTiddler := STON fromString: each contents. + tempTiddler wiki: self. + tempTiddler]) +] + { #category : #accessing } TiddlyWiki >> installJsonExporter [ @@ -718,9 +734,11 @@ TiddlyWiki >> oldestCreatedTiddler [ { #category : #accessing } TiddlyWiki >> printOn: aStream [ + | printName | + printName := self name ifNil: ['unamed']. super printOn: aStream. aStream - nextPutAll: '( ', self name ,' )' + nextPutAll: '( ', printName ,' )' ] { #category : #accessing } From 9663e41d22e6db38103792b370bc2b8897f816b6 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Tue, 2 Jul 2024 23:15:43 -0500 Subject: [PATCH 2/3] Downloading external media files. --- repository/TiddlyWiki/Tiddler.class.st | 17 ++++++++++++++--- repository/TiddlyWiki/TiddlyWiki.class.st | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/repository/TiddlyWiki/Tiddler.class.st b/repository/TiddlyWiki/Tiddler.class.st index 902297a..06fc91e 100644 --- a/repository/TiddlyWiki/Tiddler.class.st +++ b/repository/TiddlyWiki/Tiddler.class.st @@ -180,7 +180,7 @@ Tiddler >> customFieldsWithMediaLinks [ | response | response := OrderedDictionary new. self customFields keysAndValuesDo: [:k :v | - (v endsWithAnyOf: #('mp4' 'jpg' 'jpeg' 'png')) + (v endsWithAnyOf: #('mp4' 'wav' 'jpg' 'jpeg' 'png')) ifTrue: [response at: k put: v ] ]. ^ response @@ -192,8 +192,19 @@ Tiddler >> deleteUid [ ] { #category : #accessing } -Tiddler >> downloadAndIndexMediaLinksInto: aFolder [ - ^ self customFieldsWithMediaLinks +Tiddler >> downloadAndRelinkExternalMedia [ + self customFieldsWithMediaLinks + keysAndValuesDo: [:k :v | + (v endsWithAnyOf: #('mp4')) + ifTrue: [ | fileName filePath | + fileName := v asUrl segments last. + filePath := (FileLocator temp / fileName) fullName. + GtSubprocessWithInMemoryOutput new + shellCommand: 'curl -# ', v, ' -o ', filePath; + runAndWait; + stdout + ] + ] ] { #category : #accessing } diff --git a/repository/TiddlyWiki/TiddlyWiki.class.st b/repository/TiddlyWiki/TiddlyWiki.class.st index 7d77d8b..1830e8b 100644 --- a/repository/TiddlyWiki/TiddlyWiki.class.st +++ b/repository/TiddlyWiki/TiddlyWiki.class.st @@ -256,6 +256,7 @@ TiddlyWiki >> exportContentType: aMimeType [ { #category : #accessing } TiddlyWiki >> exportJSONFile [ | docTree rawJsonTiddlers | + self tiddlers isNotEmpty ifTrue: [^ self exportJSONFileFromTiddlers ]. self htmlFileExists. docTree := XMLHTMLParser parse: self file contents. rawJsonTiddlers := (docTree xpath: '//script[@class="tiddlywiki-tiddler-store"]') stringValue. @@ -264,6 +265,21 @@ TiddlyWiki >> exportJSONFile [ { #category : #accessing } TiddlyWiki >> exportJSONFileFromTiddlers [ + | response | + response := '' writeStream. + response + nextPutAll: '['; cr. + self tiddlers allButLastDo: [:tiddler | + response + nextPutAll: tiddler asJsonString; + nextPutAll: ','; cr + ]. + response + nextPutAll: self tiddlers last asJsonString; cr; + nextPutAll: ']'; cr. + ^ MarkupFile + exportAsFileOn: self folder / 'tiddlers.json' + containing: response contents ] { #category : #accessing } From 7bf281a5a6eedc779d06ce486158b58d706c29f1 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Wed, 3 Jul 2024 06:42:22 -0500 Subject: [PATCH 3/3] Relinking external media files as local files. --- repository/TiddlyWiki/Tiddler.class.st | 62 ++++++++++++++++++----- repository/TiddlyWiki/TiddlyWiki.class.st | 9 +++- 2 files changed, 57 insertions(+), 14 deletions(-) diff --git a/repository/TiddlyWiki/Tiddler.class.st b/repository/TiddlyWiki/Tiddler.class.st index 06fc91e..33e2be4 100644 --- a/repository/TiddlyWiki/Tiddler.class.st +++ b/repository/TiddlyWiki/Tiddler.class.st @@ -193,18 +193,56 @@ Tiddler >> deleteUid [ { #category : #accessing } Tiddler >> downloadAndRelinkExternalMedia [ - self customFieldsWithMediaLinks - keysAndValuesDo: [:k :v | - (v endsWithAnyOf: #('mp4')) - ifTrue: [ | fileName filePath | - fileName := v asUrl segments last. - filePath := (FileLocator temp / fileName) fullName. - GtSubprocessWithInMemoryOutput new - shellCommand: 'curl -# ', v, ' -o ', filePath; - runAndWait; - stdout - ] - ] + | mediaExtensions| + mediaExtensions := Dictionary new + at: 'audio' put: #('wav'); + at: 'video' put: #('mp4'); + at: 'image' put: #('jpg' 'jpeg' 'png'); + yourself. + self customFieldsWithMediaLinks + keysAndValuesDo: [ :k :v | + mediaExtensions keysAndValuesDo: [:kind :extensions | + (v asLowercase endsWithAnyOf: extensions) + ifTrue: [ | localFile| + self downloadLink: v for: k into: 'external/', kind , '/'. + localFile := (self wiki substitutions at: self title at: k) second. + self customFields at: k put: localFile. + ] + ] + ]. + ^ self wiki substitutions +] + +{ #category : #accessing } +Tiddler >> downloadLink: v for: k [ + | filePath fileName semiFilePath | + fileName := v asUrl segments last. + semiFilePath := 'external/video/' , fileName. + filePath := (self wiki folder / semiFilePath) fullName. + GtSubprocessWithInMemoryOutput new + shellCommand: 'curl -L -# ' , v , ' -o ' , filePath; + runAndWait; + stdout. + ^ Dictionary new + at: k + put: {v. + semiFilePath}; + yourself +] + +{ #category : #accessing } +Tiddler >> downloadLink: v for: k into: subfolder [ + | filePath fileName semiFilePath | + fileName := v asUrl segments last. + semiFilePath := subfolder , fileName. + filePath := (self wiki folder / semiFilePath) fullName. + GtSubprocessWithInMemoryOutput new + shellCommand: 'curl -L -# ' , v , ' -o ' , filePath; + runAndWait; + stdout. + ^ self wiki substitutions + at: self title at: k put: {v. semiFilePath}; + yourself ] { #category : #accessing } diff --git a/repository/TiddlyWiki/TiddlyWiki.class.st b/repository/TiddlyWiki/TiddlyWiki.class.st index 1830e8b..93be0b1 100644 --- a/repository/TiddlyWiki/TiddlyWiki.class.st +++ b/repository/TiddlyWiki/TiddlyWiki.class.st @@ -516,8 +516,8 @@ TiddlyWiki >> importJSONLink [ { #category : #accessing } TiddlyWiki >> importSTONFilesFrom: aFolder [ | tiddlerFiles | - self folder: aFolder parent. - tiddlerFiles := aFolder children + self folder: aFolder. + tiddlerFiles := (aFolder / 'tiddlers') children select: [ :localFile | localFile basename endsWith: '.ston' ]. self tiddlers: (tiddlerFiles collect: [ :each | | tempTiddler| tempTiddler := STON fromString: each contents. @@ -912,6 +912,11 @@ TiddlyWiki >> shadow [ ^ self tiddlers select: [:tiddler | tiddler title beginsWith: '$:/'] ] +{ #category : #'as yet unclassified' } +TiddlyWiki >> substitutions [ + ^ self config at: 'substitutions' ifAbsentPut: [ Dictionary new]. +] + { #category : #accessing } TiddlyWiki >> syncRemoteLocalDestructive [