From ce3b6a96a08af985f660660324a92605dbb1b09a Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Sun, 30 Jan 2022 21:54:16 -0500 Subject: [PATCH] Starting detection of remote Markdeep pages in current database. --- .../Grafoscopio-Utils/LePage.extension.st | 25 +++++++++++++++++-- .../Grafoscopio-Utils/Markdeep.class.st | 10 ++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/repository/Grafoscopio-Utils/LePage.extension.st b/repository/Grafoscopio-Utils/LePage.extension.st index 5f0bbb0..fbc4652 100644 --- a/repository/Grafoscopio-Utils/LePage.extension.st +++ b/repository/Grafoscopio-Utils/LePage.extension.st @@ -39,8 +39,23 @@ LePage >> fileName [ ] { #category : #'*Grafoscopio-Utils-Core' } -LePage >> fromMarkdeepUrl: aString [ - ^ aString asUrl retrieveContents. +LePage >> fromMarkdeepUrl: aString [ + + | markdeepHelper id remoteMetadata | + markdeepHelper := Markdeep new. + remoteMetadata := markdeepHelper metadataFromXML: (self xmlFromUrl: aString). + id := remoteMetadata at: 'id' ifAbsent: [ ^ false ]. + +] + +{ #category : #'*Grafoscopio-Utils-Core' } +LePage >> isInDocumentsDatabase: markdeepDocUrl [ + | markdeepHelper id remoteMetadata | + markdeepHelper := Markdeep new. + remoteMetadata := markdeepHelper metadataFromXML: (self xmlFromUrl: markdeepDocUrl). + id := remoteMetadata at: 'id' ifAbsent: [ ^ false ]. + self database pagesByDateToShow + detect: [ :page | page uidString = id ] ifFound: [ ^ true ] ifNone: [ ^ false ]. ] { #category : #'*Grafoscopio-Utils-Core' } @@ -87,3 +102,9 @@ LePage >> preorderTraversal [ self withDeepCollect: [:each | each allChildrenBreadthFirstDo: [:child | output add: child ] ]. ^ output. ] + +{ #category : #'*Grafoscopio-Utils-Core' } +LePage >> xmlFromUrl: aString [ + + ^ (XMLHTMLParser on: aString asUrl retrieveContents) parseDocument +] diff --git a/repository/Grafoscopio-Utils/Markdeep.class.st b/repository/Grafoscopio-Utils/Markdeep.class.st index 1801520..2fc2684 100644 --- a/repository/Grafoscopio-Utils/Markdeep.class.st +++ b/repository/Grafoscopio-Utils/Markdeep.class.st @@ -210,6 +210,16 @@ Markdeep >> metadata [ ^ metadata ifNil: [ metadata := OrderedDictionary new ] ] +{ #category : #utilities } +Markdeep >> metadataFromXML: aXMLDocument [ + | metaDict | + + metaDict := OrderedDictionary new. + (aXMLDocument xpath: '//meta') do: [ :each | + metaDict at: (each @ 'name') stringValue put: (each @ 'content') stringValue ]. + ^ metaDict +] + { #category : #printing } Markdeep >> printOn: aStream [