2022-01-22 15:23:56 +00:00
|
|
|
Extension { #name : #LePage }
|
|
|
|
|
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
|
|
|
LePage >> asMarkdeep [
|
2022-01-28 22:01:41 +00:00
|
|
|
| bodyStream markdeep |
|
2022-01-22 15:23:56 +00:00
|
|
|
bodyStream := '' writeStream.
|
|
|
|
self preorderTraversal do: [:snippet |
|
2022-01-24 01:38:07 +00:00
|
|
|
bodyStream nextPutAll: snippet asMarkdeep
|
2022-01-22 15:23:56 +00:00
|
|
|
].
|
2022-01-28 22:01:41 +00:00
|
|
|
markdeep := Markdeep new
|
2022-01-24 01:38:07 +00:00
|
|
|
title: self title;
|
2022-01-28 22:01:41 +00:00
|
|
|
body: bodyStream contents.
|
|
|
|
self metadata keysAndValuesDo: [:k :v |
|
2022-01-31 01:09:17 +00:00
|
|
|
markdeep head
|
2022-01-28 22:01:41 +00:00
|
|
|
add: '<meta name="', k, '" content="', v,'">';
|
|
|
|
yourself.
|
|
|
|
].
|
2022-01-29 03:34:33 +00:00
|
|
|
self metadata at: 'authors' ifPresent: [:author | markdeep metadata at: 'authors' put: author ].
|
|
|
|
self metadata at: 'version' ifPresent: [:version | markdeep metadata at: 'version' put: version ].
|
2022-01-28 22:01:41 +00:00
|
|
|
^ markdeep.
|
2022-01-22 15:23:56 +00:00
|
|
|
]
|
|
|
|
|
2022-01-30 18:57:25 +00:00
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
|
|
|
LePage >> asMarkdeepFile [
|
|
|
|
| folder |
|
|
|
|
folder := self options at: 'storage' ifAbsent: [ FileLocator temp ].
|
|
|
|
^ self asMarkdeep exportAsFileOn: folder / self markdeepFileName
|
|
|
|
]
|
|
|
|
|
2022-01-22 15:23:56 +00:00
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
|
|
|
LePage >> asMarkdeepInto: aFileLocator [
|
|
|
|
|
|
|
|
self preorderTraversal
|
|
|
|
]
|
2022-01-24 01:38:07 +00:00
|
|
|
|
2022-02-03 18:01:35 +00:00
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
|
|
|
LePage >> detectSnippetWithUid: uidString [
|
|
|
|
"Answer a boolean indicating whether the supplied uid is present"
|
|
|
|
|
|
|
|
^ self preorderTraversal detect: [ :snippet | snippet uidString = uidString ] ifNone: [ ^ nil ]
|
|
|
|
]
|
|
|
|
|
2022-01-24 01:38:07 +00:00
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
|
|
|
LePage >> fileName [
|
|
|
|
^ self title asDashedLowercase, '.', ((self uidString copyFrom: 1 to: 5 ) copyWithoutAll: '/'), '.md.html'
|
|
|
|
]
|
|
|
|
|
2022-01-31 01:09:17 +00:00
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
2022-02-02 23:35:39 +00:00
|
|
|
LePage >> fromMarkdeepUrl: aString [
|
|
|
|
| docTree pageMetadata |
|
|
|
|
docTree := GrafoscopioUtils xmlFromUrl: aString.
|
|
|
|
pageMetadata := Markdeep new metadataFromXML: docTree.
|
|
|
|
self
|
|
|
|
basicUid: (pageMetadata at: 'id');
|
|
|
|
title: (pageMetadata at: 'title');
|
|
|
|
createTime: (pageMetadata at: 'created');
|
|
|
|
editTime: (pageMetadata at: 'modified');
|
|
|
|
createEmail: (pageMetadata at: 'creator');
|
|
|
|
editEmail: (pageMetadata at: 'modifier');
|
|
|
|
optionAt: 'metadata' put: pageMetadata.
|
|
|
|
self populateChildrenFrom: (docTree xpath: '//div')
|
2022-01-31 02:54:16 +00:00
|
|
|
|
|
|
|
]
|
|
|
|
|
2022-01-28 19:30:56 +00:00
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
2022-01-30 18:57:25 +00:00
|
|
|
LePage >> markdeepFileName [
|
|
|
|
| sanitized |
|
|
|
|
sanitized := self title asDashedLowercase copyWithoutAll: #($/).
|
|
|
|
^ sanitized, '--',(self uidString copyFrom: 1 to: 5), '.md.html'.
|
2022-01-28 19:30:56 +00:00
|
|
|
]
|
|
|
|
|
2022-01-24 01:38:07 +00:00
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
|
|
|
LePage >> markdeepTemporalFile [
|
2022-01-30 18:57:25 +00:00
|
|
|
|
|
|
|
^ FileLocator temp / self markdeepFileName.
|
2022-01-24 01:38:07 +00:00
|
|
|
]
|
2022-01-27 14:23:34 +00:00
|
|
|
|
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
|
|
|
LePage >> metadata [
|
2022-01-28 22:01:41 +00:00
|
|
|
|
|
|
|
^ self options at: 'metadata' ifAbsentPut: [ self metadataInit]
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
|
|
|
LePage >> metadataInit [
|
|
|
|
|
2022-01-27 14:23:34 +00:00
|
|
|
^ OrderedDictionary new
|
2022-01-28 22:01:41 +00:00
|
|
|
at: 'id' put: self uidString;
|
2022-01-29 03:34:33 +00:00
|
|
|
at: 'title' put: self contentAsString;
|
2022-01-28 22:01:41 +00:00
|
|
|
at: 'created' put: self createTime asString;
|
|
|
|
at: 'modified' put: self latestEditTime asString;
|
|
|
|
at: 'creator' put: self createEmail asString;
|
|
|
|
at: 'modifier' put: self editEmail asString;
|
|
|
|
yourself
|
2022-01-27 14:23:34 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
|
|
|
LePage >> options [
|
|
|
|
^ options
|
|
|
|
]
|
2022-01-28 20:33:05 +00:00
|
|
|
|
2022-02-02 23:35:39 +00:00
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
|
|
|
LePage >> populateChildrenFrom: docTreeDivs [
|
2022-02-05 23:20:48 +00:00
|
|
|
docTreeDivs doWithIndex: [:div :i | | snippetTemp "parent surrogate" |
|
|
|
|
snippetTemp := LeSnippet fromMetaMarkdeep:div.
|
|
|
|
"self children
|
|
|
|
addSnippet: snippet beforeIndex: i."
|
|
|
|
self snippetBuilder snippet: snippetTemp; add.
|
|
|
|
"surrogate := self detectSnippetWithUid: (snippetTemp metadata at: 'parent').
|
|
|
|
parent := self snippetBuilder snippet: surrogate."
|
2022-02-02 23:35:39 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2022-01-28 20:33:05 +00:00
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
|
|
|
LePage >> preorderTraversal [
|
|
|
|
| output |
|
|
|
|
output := OrderedCollection new.
|
|
|
|
self withDeepCollect: [:each | each allChildrenBreadthFirstDo: [:child | output add: child ] ].
|
|
|
|
^ output.
|
|
|
|
]
|
2022-02-04 15:44:19 +00:00
|
|
|
|
|
|
|
{ #category : #'*Grafoscopio-Utils-Core' }
|
|
|
|
LePage >> removeSnippetsMetadata [
|
|
|
|
self preorderTraversal do: [ :snippet | snippet options removeKey: 'metadata' ]
|
|
|
|
]
|