From a5759d886daeb30a6d83474118b625faf83f36d5 Mon Sep 17 00:00:00 2001 From: Ruidajo Date: Fri, 11 Feb 2022 23:35:44 -0500 Subject: [PATCH] Improving tiddlers filtering and exporting. --- repository/TiddlyWiki/Tiddler.class.st | 9 +++- repository/TiddlyWiki/TiddlyWiki.class.st | 65 +++++++++++++++++++---- 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/repository/TiddlyWiki/Tiddler.class.st b/repository/TiddlyWiki/Tiddler.class.st index 48d5a4b..9925437 100644 --- a/repository/TiddlyWiki/Tiddler.class.st +++ b/repository/TiddlyWiki/Tiddler.class.st @@ -145,11 +145,18 @@ Tiddler >> exportJSONFile [ { #category : #accessing } Tiddler >> exportSTONFile [ + + self exportSTONFileInto: 'tiddlers' +] + +{ #category : #accessing } +Tiddler >> exportSTONFileInto: subfolder [ + | stonFile output dashedTitle sanitized date | dashedTitle := '-' join: (self title substrings collect: [ :each | each ]). sanitized := dashedTitle copyWithoutAll: #($¿ $? $! $¡ $/). date := self created hash hex copyFrom: 1 to: 5. - stonFile := self wiki file parent / 'tiddlers' / (sanitized, '--', date, '.ston'). + stonFile := self wiki file parent / subfolder / (sanitized, '--', date, '.ston'). ^ MarkupFile exportAsFileOn: stonFile containing: self asStonStringPretty ] diff --git a/repository/TiddlyWiki/TiddlyWiki.class.st b/repository/TiddlyWiki/TiddlyWiki.class.st index 94a6fc6..732ab19 100644 --- a/repository/TiddlyWiki/TiddlyWiki.class.st +++ b/repository/TiddlyWiki/TiddlyWiki.class.st @@ -80,6 +80,15 @@ TiddlyWiki >> contentTiddlers [ ^ self tiddlers copyWithoutAll: self shadow ] +{ #category : #accessing } +TiddlyWiki >> exportContentType: aMimeType [ + + | filteredTiddlers tempWiki | + filteredTiddlers := self selectContentType: aMimeType. + filteredTiddlers do: [ :each | each exportSTONFileInto: self largeTiddlersFolderName ]. + ^ self largeTiddlersFolder +] + { #category : #accessing } TiddlyWiki >> exportJSONFile [ | docTree rawJsonTiddlers | @@ -91,7 +100,14 @@ TiddlyWiki >> exportJSONFile [ { #category : #accessing } TiddlyWiki >> exportJSONSubtiddlers: subtiddlersCollection [ - ^ MarkupFile exportAsFileOn: self file parent / 'subtiddlers.json' containing: (self jsonSubtiddlers: subtiddlersCollection) + + ^ self exportJSONSubtiddlers: subtiddlersCollection as: 'subtiddlers' +] + +{ #category : #accessing } +TiddlyWiki >> exportJSONSubtiddlers: subtiddlersCollection as: aName [ + + ^ MarkupFile exportAsFileOn: self file parent / aName, 'json' containing: (self jsonSubtiddlers: subtiddlersCollection) ] { #category : #accessing } @@ -105,7 +121,7 @@ TiddlyWiki >> exportSTONFiles [ stonFile := FileLocator temp / 'tiddlers.ston' ] ifNotNil: [ stonFile := self tiddlersJSONFile withoutExtension , 'ston' ]. - shadowFile := self shadowsFolder / '_shadow.ston'. + shadowFile := self largeTiddlersFolder / '_shadow.ston'. wikiTemp := self copy. wikiTemp tiddlers: self contentTiddlers. wikiTemp := wikiTemp withoutImages. @@ -190,6 +206,24 @@ TiddlyWiki >> jsonSubtiddlers: subtiddlersCollection [ ^ STONJSON toStringPretty: subtiddlersDict ] +{ #category : #accessing } +TiddlyWiki >> largeTiddlersFolder [ + "I store all shadow tiddlers, i.e. tiddlers that provide functionality to TiddlyWiki, + for example the ones that come in the plugins or in system tiddlers. + For more information about shadow tiddlers, see #shadow method." + + | folder | + folder := self file parent / self largeTiddlersFolderName. + folder ensureCreateDirectory. + ^ folder +] + +{ #category : #accessing } +TiddlyWiki >> largeTiddlersFolderName [ + + ^ 'largeTiddlers' +] + { #category : #accessing } TiddlyWiki >> loadFromConfig: wikiname [ ^ (self configDictonary at: wikiname) importJSONFile. @@ -245,6 +279,17 @@ TiddlyWiki >> printOn: aStream [ nextPutAll: '( ', self name ,' )' ] +{ #category : #accessing } +TiddlyWiki >> rebuildTiddlersJSON [ + + | stonTiddlers stonTiddlerFiles | + stonTiddlerFiles := self tiddlersFolder asFileReference children + select: [ :each | each fullName endsWith: 'ston' ]. + stonTiddlers := stonTiddlerFiles collect: [ :each | STON fromString: each contents ]. + self tiddlers: stonTiddlers. + ^ self exportJSONSubtiddlers: self tiddlers as: 'rebuildedTiddlers'. +] + { #category : #accessing } TiddlyWiki >> remote [ @@ -257,6 +302,12 @@ TiddlyWiki >> remote: aUrlString [ remote := aUrlString asZnUrl ] +{ #category : #accessing } +TiddlyWiki >> selectContentType: mimeType [ + + ^ self tiddlers select: [ :tiddler | tiddler type isNotNil and: [tiddler type beginsWith: mimeType ]] +] + { #category : #accessing } TiddlyWiki >> shadow [ "Shadow tiddlers are tiddlers that are loaded from plugins. @@ -267,14 +318,6 @@ TiddlyWiki >> shadow [ ^ self tiddlers select: [:tiddler | tiddler title beginsWith: '$:/'] ] -{ #category : #accessing } -TiddlyWiki >> shadowsFolder [ - "I store all shadow tiddlers, i.e. tiddlers that provide functionality to TiddlyWiki, - for example the ones that come in the plugins or in system tiddlers. - For more information about shadow tiddlers, see #shadow method." - ^ self file parent / 'shadow' -] - { #category : #accessing } TiddlyWiki >> taggedWith: aTag [ ^ self tiddlers select: [:tiddler | @@ -318,7 +361,7 @@ TiddlyWiki >> tiddlersJSONUrl [ { #category : #accessing } TiddlyWiki >> withoutContentType: application [ | filteredTiddlers tempWiki | - filteredTiddlers := self tiddlers reject: [:tiddler | tiddler type isNotNil and: [tiddler type beginsWith: application] ]. + filteredTiddlers := self tiddlers reject: [:tiddler | tiddler type isNotNil and: [tiddler type beginsWith: application ]]. tempWiki := self copy tiddlers: filteredTiddlers. tempWiki tiddlers do: [:tiddler | tiddler wiki: tempWiki ].