Minimal working example of nesting page contents importation.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2023-10-28 13:28:50 -05:00
parent 55b304581c
commit 253a5df692

View File

@ -2,14 +2,14 @@ Extension { #name : #LeDatabase }
{ #category : #'*MiniDocs' } { #category : #'*MiniDocs' }
LeDatabase >> addPage2FromMarkdeep: markdeepDocTree withRemote: externalDocLocation [ LeDatabase >> addPage2FromMarkdeep: markdeepDocTree withRemote: externalDocLocation [
| remoteMetadata divSnippets dataSnippets snippets page | | remoteMetadata divSnippets dataSnippets snippets newPage |
divSnippets := (markdeepDocTree xpath: '//div[@st-class]') asOrderedCollection divSnippets := (markdeepDocTree xpath: '//div[@st-class]') asOrderedCollection
collect: [ :xmlElement | xmlElement postCopy ]. collect: [ :xmlElement | xmlElement postCopy ].
remoteMetadata := Markdeep new metadataFromXML: markdeepDocTree. remoteMetadata := Markdeep new metadataFromXML: markdeepDocTree.
remoteMetadata at: 'origin' put: externalDocLocation. remoteMetadata at: 'origin' put: externalDocLocation.
dataSnippets := self sanitizeMarkdeepSnippets: divSnippets withMetadata: remoteMetadata. dataSnippets := self sanitizeMarkdeepSnippets: divSnippets withMetadata: remoteMetadata.
snippets := dataSnippets collect: [ :each | each asLepiterSnippet ]. snippets := dataSnippets collect: [ :each | each asLepiterSnippet ].
page := LePage new newPage := LePage new
title: (remoteMetadata at: 'title'); title: (remoteMetadata at: 'title');
basicUid: (UUID fromString36: (remoteMetadata at: 'id')); basicUid: (UUID fromString36: (remoteMetadata at: 'id'));
createTime: (LeTime new time: (remoteMetadata at: 'created') asDateAndTime); createTime: (LeTime new time: (remoteMetadata at: 'created') asDateAndTime);
@ -17,8 +17,22 @@ LeDatabase >> addPage2FromMarkdeep: markdeepDocTree withRemote: externalDocLocat
latestEditTime: (LeTime new time: (remoteMetadata at: 'modified') asDateAndTime); latestEditTime: (LeTime new time: (remoteMetadata at: 'modified') asDateAndTime);
createEmail: (remoteMetadata at: 'creator'); createEmail: (remoteMetadata at: 'creator');
editEmail: (remoteMetadata at: 'modifier'). editEmail: (remoteMetadata at: 'modifier').
^ { snippets . page } "^ { snippets . page }"
"snippets do: [ :snippet | "Rebulding partial subtrees"
snippets do: [:currentSnippet | |parentSnippet|
parentSnippet := snippets
detect: [:item | item uid asString = currentSnippet parent]
ifNone: [ parentSnippet := 'unrooted' ].
currentSnippet parent: parentSnippet.
(parentSnippet class = ByteString)
ifFalse: [ parentSnippet children addChild: currentSnippet ]
].
"Adding unrooted subtrees to the page"
snippets
select: [:each | each parent = 'unrooted']
thenDo: [:unrooted | newPage addSnippet: unrooted ].
"^ newPage"
newPage childrenDo: [ :snippet |
(self hasBlockUID: snippet uid) (self hasBlockUID: snippet uid)
ifTrue: [ | existingPage | ifTrue: [ | existingPage |
existingPage := self pages existingPage := self pages
@ -27,8 +41,8 @@ LeDatabase >> addPage2FromMarkdeep: markdeepDocTree withRemote: externalDocLocat
^ self ] ^ self ]
ifFalse: [ snippet database: self. ifFalse: [ snippet database: self.
self registerSnippet: snippet ] ]. self registerSnippet: snippet ] ].
self addPage: page. self addPage: newPage.
^ page" ^ newPage
] ]
{ #category : #'*MiniDocs' } { #category : #'*MiniDocs' }
@ -86,7 +100,7 @@ LeDatabase >> addPageFromMarkdeepUrl: aString [
ifNotNil: [ :arg | ifNotNil: [ :arg |
self importErrorForLocal: page withRemote: aString. self importErrorForLocal: page withRemote: aString.
^ self ]. ^ self ].
^ self addPage2FromMarkdeep: (self docTreeForLink: aString) withRemote: aString ^ self addPageFromMarkdeep: (self docTreeForLink: aString) withRemote: aString
] ]
{ #category : #'*MiniDocs' } { #category : #'*MiniDocs' }