Importating legacy Grafoscopio notebooks: dealing with nil creation/modification timestamps.
This commit is contained in:
parent
362659b584
commit
01a68d562c
@ -23,14 +23,14 @@ LeDatabase >> addPageFromMarkdeep: markdeepDocTree withRemote: externalDocLocati
|
|||||||
| remoteMetadata divSnippets snippets page |
|
| remoteMetadata divSnippets snippets page |
|
||||||
divSnippets := (markdeepDocTree xpath: '//div[@st-class]') asOrderedCollection
|
divSnippets := (markdeepDocTree xpath: '//div[@st-class]') asOrderedCollection
|
||||||
collect: [ :xmlElement | xmlElement postCopy ].
|
collect: [ :xmlElement | xmlElement postCopy ].
|
||||||
self sanitizeMarkdeepSnippets: divSnippets.
|
remoteMetadata := Markdeep new metadataFromXML: markdeepDocTree.
|
||||||
|
divSnippets := self sanitizeMarkdeepSnippets: divSnippets withMetadata: remoteMetadata.
|
||||||
snippets := divSnippets
|
snippets := divSnippets
|
||||||
collect: [ :xmlElement |
|
collect: [ :xmlElement |
|
||||||
(xmlElement attributes at: 'st-class') = 'LeTextSnippet'
|
(xmlElement attributes at: 'st-class') = 'LeTextSnippet'
|
||||||
ifTrue: [ LeTextSnippet new contentFrom: xmlElement ]
|
ifTrue: [ LeTextSnippet new contentFrom: xmlElement ]
|
||||||
ifFalse: [ (xmlElement attributes at: 'st-class') = 'LePharoSnippet'
|
ifFalse: [ (xmlElement attributes at: 'st-class') = 'LePharoSnippet'
|
||||||
ifTrue: [ LePharoSnippet new contentFrom: xmlElement ] ] ].
|
ifTrue: [ LePharoSnippet new contentFrom: xmlElement ] ] ].
|
||||||
remoteMetadata := Markdeep new metadataFromXML: markdeepDocTree.
|
|
||||||
page := LePage new
|
page := LePage new
|
||||||
title: (remoteMetadata at: 'title');
|
title: (remoteMetadata at: 'title');
|
||||||
basicUid: (UUID fromString36: (remoteMetadata at: 'id'));
|
basicUid: (UUID fromString36: (remoteMetadata at: 'id'));
|
||||||
@ -181,3 +181,31 @@ LeDatabase >> options [
|
|||||||
|
|
||||||
^ options
|
^ options
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #'*MiniDocs' }
|
||||||
|
LeDatabase >> previewSanitizedPageFromMarkdeep: markdeepDocTree withRemote: externalDocLocation [
|
||||||
|
| remoteMetadata divSnippets divSnippetsSanitized |
|
||||||
|
divSnippets := (markdeepDocTree xpath: '//div[@st-class]') asOrderedCollection
|
||||||
|
collect: [ :xmlElement | xmlElement postCopy ].
|
||||||
|
remoteMetadata := Markdeep new metadataFromXML: markdeepDocTree.
|
||||||
|
divSnippetsSanitized := self sanitizeMarkdeepSnippets: divSnippets withMetadata: remoteMetadata.
|
||||||
|
^ { divSnippets . divSnippetsSanitized . remoteMetadata }
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'*MiniDocs' }
|
||||||
|
LeDatabase >> sanitizeMarkdeepSnippets: divSnippets withMetadata: remoteMetadata [
|
||||||
|
^ divSnippets collectWithIndex: [:markdeepDiv :i | | snippetData creationTime modificationTime |
|
||||||
|
snippetData := markdeepDiv asSnippetDictionary.
|
||||||
|
creationTime := snippetData at: 'created'.
|
||||||
|
modificationTime := snippetData at: 'modified'.
|
||||||
|
(creationTime = 'nil' and: [ modificationTime ~= 'nil' ])
|
||||||
|
ifTrue: [ snippetData redefineTimestampsBefore: modificationTime ].
|
||||||
|
(creationTime = 'nil' and: [ modificationTime = 'nil' ])
|
||||||
|
ifTrue: [ | timeDiff |
|
||||||
|
timeDiff := divSnippets size - i. "Suggesting that last snippets were modified after the first ones."
|
||||||
|
modificationTime := (remoteMetadata at: 'created') asDateAndTime - timeDiff seconds.
|
||||||
|
snippetData redefineTimestampsBefore: modificationTime.
|
||||||
|
].
|
||||||
|
snippetData.
|
||||||
|
]
|
||||||
|
]
|
||||||
|
13
src/MiniDocs/OrderedDictionary.extension.st
Normal file
13
src/MiniDocs/OrderedDictionary.extension.st
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
Extension { #name : #OrderedDictionary }
|
||||||
|
|
||||||
|
{ #category : #'*MiniDocs' }
|
||||||
|
OrderedDictionary >> redefineTimestampsBefore: dateAndTime [
|
||||||
|
self at: 'modified' put: dateAndTime asDateAndTime.
|
||||||
|
self at: 'created' put: dateAndTime asDateAndTime - 1 second.
|
||||||
|
self at: 'errata' ifAbsentPut: [ | initErrata |
|
||||||
|
initErrata := OrderedCollection new.
|
||||||
|
initErrata add: 'Modified timestamps: created/modified date and time were replaced instead of nil values. See "origin" key for more traceability info.'.
|
||||||
|
initErrata
|
||||||
|
].
|
||||||
|
|
||||||
|
]
|
30
src/MiniDocs/XMLElement.extension.st
Normal file
30
src/MiniDocs/XMLElement.extension.st
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
Extension { #name : #XMLElement }
|
||||||
|
|
||||||
|
{ #category : #'*MiniDocs' }
|
||||||
|
XMLElement >> asSnippetDictionary [
|
||||||
|
| response |
|
||||||
|
response := STON fromString: (self attributes at: 'st-data').
|
||||||
|
response at: 'className' put: (self attributes at: 'st-class').
|
||||||
|
response at: 'content' put: self sanitizedContent.
|
||||||
|
^ response
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'*MiniDocs' }
|
||||||
|
XMLElement >> sanitizedContent [
|
||||||
|
| className sanitizedText |
|
||||||
|
className := self attributes at: 'st-class'.
|
||||||
|
(className = 'LeTextSnippet') ifTrue: [
|
||||||
|
sanitizedText := self contentString.
|
||||||
|
sanitizedText := sanitizedText allButFirst.
|
||||||
|
sanitizedText := sanitizedText allButLast.
|
||||||
|
].
|
||||||
|
(className = 'LePharoSnippet') ifTrue: [ | joinedText |
|
||||||
|
sanitizedText := self contentString lines.
|
||||||
|
sanitizedText := sanitizedText copyFrom: 4 to: sanitizedText size -2.
|
||||||
|
joinedText := '' writeStream.
|
||||||
|
sanitizedText do: [ :line | joinedText nextPutAll: line; nextPut: Character lf ].
|
||||||
|
sanitizedText := joinedText contents allButLast.
|
||||||
|
].
|
||||||
|
^ sanitizedText
|
||||||
|
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user