TiddlyWikiPharo/repository/TiddlyWiki/TiddlyWiki.class.st

828 lines
23 KiB
Smalltalk
Raw Normal View History

2021-02-23 17:01:54 +00:00
"
I model a TiddlyWiki.
More information:
https://tiddlywiki.com/
"
Class {
#name : #TiddlyWiki,
#superclass : #Object,
2021-02-23 17:01:54 +00:00
#instVars : [
'name',
'file',
'remote',
'jsonFile',
'tiddlers',
'folder'
2021-02-23 17:01:54 +00:00
],
#category : #'TiddlyWiki-Model'
2021-02-23 17:01:54 +00:00
}
{ #category : #'instance - creation' }
TiddlyWiki class >> createFromRemote: aRemoteTWUrl in: aFolder [
| wiki |
aFolder hasChildren ifTrue: [ ^ nil ].
wiki := TiddlyWiki new
remote: aRemoteTWUrl;
folder: aFolder;
file: (aFolder / 'index.html') ensureCreateFile.
^ wiki downloadHTML;
tiddlers.
]
{ #category : #'instance - creation' }
TiddlyWiki class >> createFromRemote: aRemoteTWUrl in: aFolder named: aNameString [
| wiki |
wiki := self createFromRemote: aRemoteTWUrl in: aFolder.
^ wiki ifNotNil: [ ^ wiki name: aNameString ]
]
{ #category : #accessing }
TiddlyWiki class >> fromJSONUrl: anUrlString [
| rawContents contentsString |
rawContents := anUrlString asUrl retrieveContents.
rawContents class = ByteArray
ifTrue: [ contentsString := rawContents utf8Decoded ]
ifFalse: [ contentsString := rawContents ].
^ self new
fromDictionary: (STONJSON fromString: contentsString);
remote: anUrlString;
name: anUrlString
]
{ #category : #accessing }
TiddlyWiki >> addRecentChangesToRepo [
| docsSton docsStonSanitized recentTiddlers repository |
repository := self repository.
2022-03-17 20:24:01 +00:00
self updateFromHtml.
recentTiddlers := self changesAfter: repository checkoutDateAndTime.
2022-03-17 20:25:25 +00:00
docsSton := recentTiddlers collect: [:each | each exportSTONFileOptimized ].
"Collecting tiddlers file reference as string and adding to the repo"
docsStonSanitized := docsSton collect: [ :each |
(each fullName removePrefix: repository localRoot) allButFirst ].
docsStonSanitized do: [ :each | repository add: each ].
^ repository status
]
{ #category : #accessing }
2021-09-16 00:21:53 +00:00
TiddlyWiki >> addToConfigFile [
| cleaned newConfig |
2021-09-16 00:21:53 +00:00
cleaned := self copy.
cleaned tiddlers: nil.
newConfig := self configDictonary
2021-09-16 00:21:53 +00:00
at: cleaned name put: cleaned;
yourself.
^ MarkupFile exportAsFileOn: self configFile containing:(STON toStringPretty: newConfig)
2021-09-16 00:37:57 +00:00
]
{ #category : #accessing }
TiddlyWiki >> addUnversionedLargeTiddlersToRepo [
| stonfiles largeTiddlersFileReference repository |
repository := self repository.
stonfiles := (self file parent / 'largeTiddlers') files
select: [ :each | each fullName endsWith: '.ston' ].
largeTiddlersFileReference := stonfiles collect: [ :each |
each fullName withoutPrefix:
repository local fullName , '/' ].
largeTiddlersFileReference do: [ :each | repository addUnversioned: each ].
^ largeTiddlersFileReference
]
{ #category : #testing }
TiddlyWiki >> belongsToLocalRepository [
| localFolder tempRepo relativeName |
localFolder := self detectRepositoryLocal ifNil: [ ^ false ].
tempRepo := FossilRepo new
local: localFolder.
relativeName := self file fullName withoutPrefix: (tempRepo local fullName, '/').
^ tempRepo listUnversioned hasLiteral: relativeName
]
2022-02-04 16:47:53 +00:00
{ #category : #accessing }
2022-02-11 20:43:43 +00:00
TiddlyWiki >> changesAfter: aDateString [
2022-02-04 16:47:53 +00:00
2022-02-11 20:43:43 +00:00
| recent created modified wiki aDate |
aDate := aDateString asZTimestamp.
wiki := self commonTiddlers.
created := wiki select: [ :tiddler | tiddler created asZTimestamp > aDate ].
2022-02-04 16:47:53 +00:00
modified := wiki select: [ :tiddler | tiddler modified isNotNil
and: [ tiddler modified asZTimestamp > aDate ] ].
2022-02-04 16:47:53 +00:00
recent := OrderedCollection new.
recent
addAll: created;
addAll: modified.
^ recent asSet.
2022-02-04 16:47:53 +00:00
]
{ #category : #accessing }
TiddlyWiki >> commonTiddlers [
| content |
content := OrderedCollection new.
content
addAll: (self contentTiddlers
select: [ :each | each isTW5Type or: [ each isNilType ]]);
"addAll: (self contentTiddlers select: [ :each | each isJavascript ]);"
addAll: (self contentTiddlers select: [ :each | each isXTiddlerDictionary ]);
addAll: (self contentTiddlers select: [ :each | each isTextPlain ]);
addAll: (self contentTiddlers select: [ :each | each isMarkdown ]).
^ content.
]
{ #category : #accessing }
2021-09-16 00:37:57 +00:00
TiddlyWiki >> configDictonary [
^ STONJSON fromString: self configFile contents.
2021-09-16 00:21:53 +00:00
]
{ #category : #accessing }
2021-09-16 00:21:53 +00:00
TiddlyWiki >> configFile [
| tempFile |
tempFile := FileLocator home / '.config' / 'TiddlyWikiPharo' / 'tiddlywiki.conf.ston'.
tempFile ensureCreateFile.
tempFile contents isEmpty ifTrue: [
MarkupFile exportAsFileOn: tempFile containing: ( STON toStringPretty: Dictionary new)
].
^ tempFile
]
{ #category : #accessing }
TiddlyWiki >> contentTiddlers [
^ self tiddlers copyWithoutAll: self shadow
]
2022-03-03 22:50:56 +00:00
{ #category : #accessing }
TiddlyWiki >> detectRepositoryLocal [
2022-03-03 22:50:56 +00:00
| wikiFolder folderItems |
wikiFolder := self folder.
folderItems := wikiFolder children.
2022-03-04 15:38:15 +00:00
[(folderItems select: [ :path | (path basename beginsWith: '.fslckout') or:
[ path basename beginsWith: '.fossil']]) isEmpty
and:[ (wikiFolder = FileLocator root) not ]]
whileTrue: [wikiFolder := wikiFolder parent.
folderItems := wikiFolder children.].
wikiFolder = FileLocator root ifTrue: [ ^ nil ].
^ wikiFolder
2022-03-03 22:50:56 +00:00
]
{ #category : #accessing }
TiddlyWiki >> downloadHTML [
| htmlLink localCopy |
self isInTiddlyHost ifTrue: [
htmlLink := self remote asString
].
localCopy := self folder / 'index.html'.
localCopy exists ifTrue: [ | timestamp |
timestamp := (DateAndTime now asString) copyReplaceAll: ':' with: '_'.
localCopy renameTo: 'index', timestamp, '.html'].
ZnClient new
url: htmlLink;
downloadTo: self folder / 'index.html'.
^ self folder
]
2022-03-03 19:53:00 +00:00
{ #category : #accessing }
TiddlyWiki >> exportCommonTiddlers [
2022-03-03 19:53:00 +00:00
| content |
content := self commonTiddlers.
content do: [ :each |
each exportSTONFile ].
^ self tiddlersFolder
2022-03-03 19:53:00 +00:00
]
{ #category : #accessing }
TiddlyWiki >> exportContentShadowAndLargeTiddlersSTONFiles [
2022-03-03 19:53:00 +00:00
self exportSTONFiles; exportLargeTiddlers
]
{ #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 |
self htmlFileExists.
docTree := XMLHTMLParser parse: self file contents.
rawJsonTiddlers := (docTree xpath: '//script[@class="tiddlywiki-tiddler-store"]') stringValue.
^ MarkupFile exportAsFileOn: self jsonFile containing: rawJsonTiddlers
]
{ #category : #accessing }
TiddlyWiki >> exportJSONFileOptimized [
| exporter wikiFolder |
wikiFolder := self file parent.
exporter := wikiFolder / 'scripts' / 'exportJsonFile'.
2022-03-14 15:23:50 +00:00
exporter exists ifFalse: [ self installJsonExporter ].
2022-03-07 22:29:59 +00:00
OSSUnixSubprocess new
command: exporter fullName;
2022-03-07 19:04:09 +00:00
workingDirectory: exporter parent fullName;
runAndWaitOnExitDo: [ :process :outString | ^ self jsonFile ]
]
{ #category : #accessing }
TiddlyWiki >> exportJSONFromRebuildedCommonTiddlers [
| rebuildedTiddlersJSON dateNowString wikiFolder|
wikiFolder := self folder.
dateNowString := (DateAndTime now asLocalStringYMDHM copyReplaceAll: ':' with: '-') copyReplaceAll: ' ' with: '-'.
rebuildedTiddlersJSON := '[', (',' join: (self rebuildWithoutLargeTiddlers collect: [ :each | each asJsonString ])), ']'.
^ MarkupFile exportAsFileOn: wikiFolder / 'rebuildedCommonTiddlers', dateNowString, 'json' containing: rebuildedTiddlersJSON
]
{ #category : #accessing }
TiddlyWiki >> exportJSONFromTiddlersInSubfolder: subfolder [
| rebuildedTiddlersJSON dateNowString |
dateNowString := (DateAndTime now asLocalStringYMDHM copyReplaceAll: ':' with: '-') copyReplaceAll: ' ' with: '-'.
rebuildedTiddlersJSON := '[', (',' join: ((self rebuildTiddlersFromSubfolder: subfolder) collect: [ :each | each asJsonString ])), ']'.
^ MarkupFile exportAsFileOn: subfolder / 'rebuildedTiddlers', dateNowString, 'json' containing: rebuildedTiddlersJSON
]
{ #category : #accessing }
2021-10-06 00:26:17 +00:00
TiddlyWiki >> exportJSONSubtiddlers: subtiddlersCollection [
^ self exportJSONSubtiddlers: subtiddlersCollection as: 'subtiddlers'
]
{ #category : #accessing }
TiddlyWiki >> exportJSONSubtiddlers: subtiddlersCollection as: aName [
^ MarkupFile exportAsFileOn: self file parent / aName, 'json' containing: (self jsonSubtiddlers: subtiddlersCollection)
2021-10-06 00:26:17 +00:00
]
{ #category : #'export - json' }
TiddlyWiki >> exportJSONTiddlersTagged: aTag in: aFolder [
| dateNowString |
dateNowString := (DateAndTime now asLocalStringYMDHM copyReplaceAll: ':' with: '-') copyReplaceAll: ' ' with: '-'.
^ self exportJSONTiddlersTagged: aTag in: aFolder named: (self name, '-tagged-', aTag, '-', dateNowString)
]
{ #category : #'export - json' }
TiddlyWiki >> exportJSONTiddlersTagged: aTag in: aFolder named: aFileName [
| taggedTiddlers jsonString |
2022-10-12 13:13:49 +00:00
self tiddlers.
taggedTiddlers := self taggedWith: aTag.
jsonString := '[', (',' join: (taggedTiddlers collect: [ :each | each asJsonString ])), ']'.
^ MarkupFile exportAsFileOn: aFolder / (aFileName, '.json') containing: jsonString
]
{ #category : #accessing }
TiddlyWiki >> exportJSTiddlers [
| jsTiddlers jsNotShadow |
jsTiddlers := self tiddlers select: [ :each | each isJavascript ].
jsNotShadow := jsTiddlers reject: [ :each | each isShadow ].
^ jsNotShadow do: [ :each | each exportSTONFileInto: 'tiddlers' ]
]
{ #category : #accessing }
TiddlyWiki >> exportLargeTiddlers [
^ self largeTiddlers do: [ :each |
each exportSTONFileInto: self largeTiddlersFolderName ].
]
{ #category : #accessing }
TiddlyWiki >> exportSTONFiles [
| stonFile wikiTemp shadowFile |
self tiddlersJSONFile
ifNil: [
self inform:
'No JSON Tiddlers file found. If you have one, please provide its location'.
stonFile := FileLocator temp / 'tiddlers.ston' ]
ifNotNil: [
2022-03-03 19:53:00 +00:00
stonFile := self tiddlersJSONFile withoutExtension , 'ston' ].
shadowFile := self largeTiddlersFolder / '_shadow.ston'.
wikiTemp := self copy.
wikiTemp tiddlers: self commonTiddlers.
GrafoscopioUtils exportAsSton: self shadow on: shadowFile.
^ GrafoscopioUtils exportAsSton: wikiTemp on: stonFile
]
{ #category : #accessing }
TiddlyWiki >> exportSTONTiddlers: aCollection [
aCollection do: [:each | each exportSTONFile ]
2021-09-01 23:58:15 +00:00
]
{ #category : #accessing }
TiddlyWiki >> exportTW5Tiddlers [
| tw5Tiddlers tw5ExplicitTiddlers notShadowTiddlers |
tw5Tiddlers := self tiddlers select: [ :each | each isNilType ].
tw5ExplicitTiddlers := self tiddlers select: [ :each | each isTW5Type ].
notShadowTiddlers := OrderedCollection new.
notShadowTiddlers addAll: (tw5ExplicitTiddlers reject: [ :each | each isShadow ]).
notShadowTiddlers addAll: (tw5Tiddlers reject: [ :each | each isShadow ]).
^ notShadowTiddlers do: [ :each | each exportSTONFileInto: 'tiddlers' ]
]
{ #category : #accessing }
2021-07-15 22:45:53 +00:00
TiddlyWiki >> file [
^ file ifNil: [ file := self folder / 'index.html' ]
2021-07-15 22:45:53 +00:00
]
{ #category : #accessing }
2021-07-15 22:45:53 +00:00
TiddlyWiki >> file: anObject [
file := anObject
]
2022-03-17 20:25:25 +00:00
{ #category : #accessing }
TiddlyWiki >> folder [
folder ifNotNil: [ ^ folder ].
self file
ifNotNil: [ folder := self file parent ]
ifNil: [ folder := FileLocator temp ]
]
{ #category : #accessing }
TiddlyWiki >> folder: anObject [
folder := anObject
2022-03-17 20:25:25 +00:00
]
{ #category : #accessing }
TiddlyWiki >> fromDictionary: tiddlersDict [
self tiddlers: (tiddlersDict collect: [ :each |
Tiddler new
fromDictionary: each;
wiki: self ])
]
2022-09-22 00:09:37 +00:00
{ #category : #accessing }
TiddlyWiki >> fromString: aJSONString [
| tiddlersDict |
tiddlersDict := STONJSON fromString: aJSONString.
self fromDictionary: tiddlersDict
]
{ #category : #accessing }
TiddlyWiki >> fromUrl: anUrlString [
| docTree rawJsonTiddlers tiddlersDictionary |
self remote: anUrlString.
docTree := XMLHTMLParser parse: (self remote retrieveContents).
rawJsonTiddlers := (docTree xpath: '//script[@class="tiddlywiki-tiddler-store"]') stringValue.
tiddlersDictionary := STONJSON fromString: rawJsonTiddlers.
self fromDictionary: tiddlersDictionary
]
{ #category : #accessing }
TiddlyWiki >> getRemoteTiddlers [
| remoteTiddlers localTiddlers |
remoteTiddlers := self importJSONLink tiddlers.
localTiddlers := self rebuildWithoutLargeTiddlers asArray.
"^ self recentCommonTiddlersChanged"
localTiddlers do: [ :each | | remoteTiddler |
remoteTiddler := remoteTiddlers detect: [:tiddler | tiddler title = each title].
remoteTiddler customFields at: 'uid' put: (each customFields at: 'uid').
].
self tiddlers: remoteTiddlers.
^ self recentCommonTiddlersChanged
]
{ #category : #accessing }
TiddlyWiki >> htmlFileExists [
self file ifNil: [
self inform: 'No TiddlyWiki HTML file found. If you have one, please provide its location.'.
^ nil
].
]
{ #category : #accessing }
TiddlyWiki >> importJSONFile [
"I import a JSON representation of my tiddlers data,
that has been previosly exported by
#exportJSONFileOptimized or #exportJSONFile"
2022-09-22 00:09:37 +00:00
2021-08-11 17:10:53 +00:00
self tiddlersJSONFile ifNil: [ ^ self ].
2022-09-22 00:09:37 +00:00
self fromString: self tiddlersJSONFile contents.
]
{ #category : #accessing }
TiddlyWiki >> importJSONLink [
jsonFile := self folder / 'tiddlers.json'.
self
name;
file.
MarkupFile exportAsFileOn: jsonFile containing: self remoteTiddlersContentsString.
^ self fromString: self remoteTiddlersContentsString
2021-08-11 17:10:53 +00:00
]
2021-02-23 17:01:54 +00:00
{ #category : #accessing }
TiddlyWiki >> installJsonExporter [
2022-03-07 19:04:09 +00:00
| folder |
folder := (self file parent / 'scripts') ensureCreateDirectory.
ZnClient new
url: 'https://mutabit.com/repos.fossil/mutabit/uv/wiki/scripts/exportJsonFile';
downloadTo: folder / 'exportJsonFile'.
ZnClient new
url: 'https://mutabit.com/repos.fossil/mutabit/doc/trunk/wiki/scripts/exportJsonFile.nim';
downloadTo: folder / 'exportJsonFile.nim'.
2022-03-07 19:04:09 +00:00
OSSUnixSubprocess new
command: 'chmod';
arguments: { '+x' . (folder / 'exportJsonFile') fullName };
workingDirectory: folder fullName;
redirectStdout;
redirectStderr;
runAndWaitOnExitDo: [ :process :outString | ^ outString ]
]
{ #category : #accessing }
TiddlyWiki >> isInTiddlyHost [
self remote ifNil: [ ^ false ].
2022-09-27 01:34:34 +00:00
^ self remote host endsWith: 'tiddlyhost.com'
]
{ #category : #accessing }
TiddlyWiki >> jsonFile [
^ jsonFile ifNil: [
self htmlFileExists ifNotNil:
[ jsonFile := file parent / 'tiddlers.json' ]
]
]
{ #category : #accessing }
TiddlyWiki >> jsonFile: aFileLocator [
"I contain the tiddlers representation of the wiki data in JSON format."
jsonFile := aFileLocator
]
{ #category : #accessing }
2021-10-06 00:26:17 +00:00
TiddlyWiki >> jsonSubtiddlers: subtiddlersCollection [
| subtiddlersDict |
2022-03-19 00:09:44 +00:00
subtiddlersDict := subtiddlersCollection asArray collect: [:tiddler | tiddler asDictionary ].
2021-10-06 00:26:17 +00:00
^ STONJSON toStringPretty: subtiddlersDict
]
{ #category : #accessing }
TiddlyWiki >> largeTiddlers [
| wikiImages wikiPDFs wikiLargeTiddlers |
wikiImages := self selectContentType: 'image/'.
wikiPDFs := self selectContentType: 'application/pdf'.
wikiLargeTiddlers := OrderedCollection new.
wikiLargeTiddlers
addAll: wikiImages;
addAll: wikiPDFs.
^ wikiLargeTiddlers
]
{ #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 }
2021-09-16 00:37:57 +00:00
TiddlyWiki >> loadFromConfig: wikiname [
2021-11-10 15:28:42 +00:00
^ (self configDictonary at: wikiname) importJSONFile.
2021-09-16 00:37:57 +00:00
]
{ #category : #accessing }
TiddlyWiki >> local [
^ self file
]
{ #category : #accessing }
TiddlyWiki >> local: aFileRefence [
^ self file:aFileRefence
]
{ #category : #accessing }
TiddlyWiki >> name [
| tempName suffix |
name ifNotNil: [ ^ name ].
self remote ifNil: [ ^ name := nil ].
(self remote host endsWith: 'tiddlyhost.com')
ifTrue: [ ^ name := (self remote host splitOn: '.') first ].
self file ifNotNil: [ ^ name := self file basenameWithoutExtension ].
tempName := self remote file.
(tempName endsWithAnyOf: #('.html' '.htm'))
ifTrue: [
suffix := (tempName splitOn: '.') last.
tempName := tempName removeSuffix: '.', suffix.
].
name := tempName
]
{ #category : #accessing }
TiddlyWiki >> name: aString [
name := aString
]
{ #category : #accessing }
2021-08-17 18:24:00 +00:00
TiddlyWiki >> networkView [
| view |
view := GtMondrian new.
view nodes
with: self tiddlers.
view edges
connectFromAll: #linkedTiddlers.
view layout force.
^ view
]
{ #category : #accessing }
TiddlyWiki >> oldestCreatedTiddler [
| tiddlersTemp oldestDate |
tiddlersTemp := self tiddlers.
oldestDate := (tiddlersTemp collect: [ :tiddler | tiddler created asDateAndTimeForTiddler ]) asSortedCollection first.
^ (tiddlersTemp select:[ :tiddler | tiddler created asDateAndTimeForTiddler = oldestDate ]) first.
]
{ #category : #accessing }
2021-08-11 17:10:53 +00:00
TiddlyWiki >> printOn: aStream [
super printOn: aStream.
aStream
nextPutAll: '( ', self name ,' )'
2021-02-23 17:01:54 +00:00
]
{ #category : #accessing }
TiddlyWiki >> rebuildTiddlers [
| stonTiddlers shadowTiddlersFile |
shadowTiddlersFile := self largeTiddlersFolder asFileReference children
select: [ :each | each basename beginsWith: '_shadow.ston' ].
stonTiddlers := OrderedCollection new.
stonTiddlers
addAll: self rebuildWithoutShadows ;
addAll: (STON fromString:shadowTiddlersFile first contents).
^ stonTiddlers
]
{ #category : #accessing }
TiddlyWiki >> rebuildTiddlersFromSubfolder: subfolder [
| stonTiddlers contentTiddlersFiles |
contentTiddlersFiles := subfolder children
select: [ :each | each basename endsWith: 'ston' ].
stonTiddlers := OrderedCollection new.
stonTiddlers
addAll: (contentTiddlersFiles
collect:[ :each | STONJSON fromString: each contents ]).
stonTiddlers collect: [ :tiddler | tiddler wiki: self ].
^ stonTiddlers
]
{ #category : #accessing }
TiddlyWiki >> rebuildTiddlersJSON [
self tiddlers: self rebuildWithoutShadows.
^ self exportJSONSubtiddlers:
(self rebuildWithoutShadows) as: 'rebuildedTiddlers'.
]
2022-03-04 15:38:15 +00:00
{ #category : #accessing }
TiddlyWiki >> rebuildWithoutLargeTiddlers [
2022-03-04 15:38:15 +00:00
| stonTiddlers contentTiddlersFiles |
contentTiddlersFiles := self tiddlersFolder files
select: [ :each | each basename endsWith: 'ston' ].
stonTiddlers := OrderedCollection new.
stonTiddlers
addAll: (contentTiddlersFiles
collect:[ :each | STONJSON fromString: each contents ]).
stonTiddlers collect: [ :tiddler | tiddler wiki: self ].
^ stonTiddlers
]
{ #category : #accessing }
TiddlyWiki >> rebuildWithoutShadows [
| stonTiddlers largeTiddlersRebuild |
largeTiddlersRebuild := (((self largeTiddlersFolder files)
reject: [ :each | each basename beginsWith: '_shadow' ])
collect: [ :each | STONJSON fromString: each contents ]).
stonTiddlers := OrderedCollection new.
stonTiddlers
addAll: largeTiddlersRebuild;
addAll: self rebuildWithoutLargeTiddlers.
2022-03-04 15:38:15 +00:00
^ stonTiddlers
]
{ #category : #accessing }
TiddlyWiki >> recentCommonTiddlersChanged [
^ self commonTiddlers sort: [ :tiddler1 :tiddler2 |
(tiddler1 modified isNil
ifTrue: [ tiddler1 created asDateAndTimeForTiddler ]
ifFalse: [ tiddler1 modified asDateAndTimeForTiddler ])
>
(tiddler2 modified isNil
ifTrue: [ tiddler2 created asDateAndTimeForTiddler ]
ifFalse: [ tiddler2 modified asDateAndTimeForTiddler ]) ]
]
{ #category : #accessing }
TiddlyWiki >> remote [
^ remote
]
{ #category : #accessing }
TiddlyWiki >> remote: aUrlString [
remote := aUrlString asZnUrl
]
{ #category : #accessing }
TiddlyWiki >> remoteTiddlersContentsString [
self isInTiddlyHost ifFalse: [ ^ self ].
^ (self remote asString, '/tiddlers.json') asZnUrl retrieveContents.
]
{ #category : #accessing }
TiddlyWiki >> repository [
| repo |
self belongsToLocalRepository ifFalse: [ ^ self ].
repo := FossilRepo new
local: self detectRepositoryLocal.
repo repository.
^ repo
]
2022-03-04 15:38:15 +00:00
{ #category : #accessing }
TiddlyWiki >> resynchronizeWithRepository [
2022-03-04 15:38:15 +00:00
| repository return |
2022-03-04 15:38:15 +00:00
repository := self repository.
repository update.
repository syncUnversioned.
return := Dictionary new
at: 'status' put: self addRecentChangesToRepo.
self exportSTONFiles;
exportCommonTiddlers;
exportLargeTiddlers.
^ return
2022-03-04 16:10:16 +00:00
at: 'file' put: self rebuildTiddlersJSON;
yourself.
2022-03-04 15:38:15 +00:00
]
2022-03-12 17:51:08 +00:00
{ #category : #accessing }
TiddlyWiki >> selectByTagsIncludes: string [
^ (self tiddlers select: [ :tiddler | tiddler tags notNil ])
select: [ :tiddler | tiddler tags includesSubstring: string ]
]
{ #category : #accessing }
TiddlyWiki >> selectContentType: mimeType [
^ self tiddlers select: [ :tiddler | tiddler type isNotNil and: [tiddler type beginsWith: mimeType ]]
]
2022-03-12 17:51:08 +00:00
{ #category : #accessing }
TiddlyWiki >> selectTitleIncludes: string [
^ self tiddlers select: [ :tiddler | tiddler title includesSubstring: string ]
]
{ #category : #accessing }
TiddlyWiki >> shadow [
"Shadow tiddlers are tiddlers that are loaded from plugins.
For more information about them, see:
- https://tiddlywiki.com/static/ShadowTiddlers.html
- https://groups.google.com/g/TiddlyWiki/c/HuyZmaRJTxI"
^ self tiddlers select: [:tiddler | tiddler title beginsWith: '$:/']
]
{ #category : #accessing }
TiddlyWiki >> syncRemoteLocalDestructive [
| repository |
repository := self repository.
repository update.
repository revertRemoteUnversioned.
repository exportHTMLUnversioned.
self
exportJSONFile;
importJSONFile.
self exportSTONFiles.
self exportCommonTiddlers.
self exportLargeTiddlers.
^ Dictionary new
at: 'status' put: repository status;
at: 'tiddlers from STON' put: self rebuildTiddlers;
yourself.
]
{ #category : #accessing }
TiddlyWiki >> taggedWith: aTag [
^ self tiddlers select: [:tiddler |
tiddler tags isNotNil and: [tiddler tags includesSubstring: aTag ]
]
]
{ #category : #accessing }
2021-02-23 17:01:54 +00:00
TiddlyWiki >> tiddlers [
tiddlers ifNotNil: [ ^ tiddlers ].
self isInTiddlyHost ifTrue: [ ^ self importJSONLink].
2021-02-23 17:01:54 +00:00
^ tiddlers ifNil: [ tiddlers := OrderedCollection new ]
]
{ #category : #accessing }
2021-02-23 17:01:54 +00:00
TiddlyWiki >> tiddlers: anOrderedCollection [
tiddlers := anOrderedCollection
]
2021-07-15 22:45:53 +00:00
2022-02-04 16:47:53 +00:00
{ #category : #accessing }
TiddlyWiki >> tiddlersFolder [
^ self folder / 'tiddlers'
2022-02-04 16:47:53 +00:00
]
{ #category : #accessing }
2021-07-15 22:45:53 +00:00
TiddlyWiki >> tiddlersJSONFile [
self jsonFile exists ifFalse: [
self inform: 'You need to export tiddlers as JSON from TiddlyWiki and locate it in the same folder as the HTML file'.
^ nil
].
^ jsonFile
2021-07-15 22:45:53 +00:00
]
{ #category : #accessing }
TiddlyWiki >> tiddlersJSONUrl [
self remote ifNil: [^ nil].
]
{ #category : #accessing }
TiddlyWiki >> updateFromHtml [
self
exportJSONFileOptimized;
importJSONFile.
]
{ #category : #accessing }
TiddlyWiki >> withoutContentType: application [
| filteredTiddlers tempWiki |
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 ].
^ tempWiki
]
2021-11-30 19:39:25 +00:00
{ #category : #accessing }
TiddlyWiki >> withoutImages [
^ self withoutContentType: 'image/'
2021-11-30 19:39:25 +00:00
]
{ #category : #accessing }
TiddlyWiki >> withoutPDFs [
^ self withoutContentType: 'application/pdf'
2021-11-30 19:39:25 +00:00
]