diff --git a/src/MiniDocs/PubPub.class.st b/src/MiniDocs/PubPub.class.st index ab4a05b..fb78386 100644 --- a/src/MiniDocs/PubPub.class.st +++ b/src/MiniDocs/PubPub.class.st @@ -91,6 +91,13 @@ PubPub >> extractRawTableOfContents [ ^ self extractAllContentsRaw first xpath: '//div[contains(concat(" ",normalize-space(@class)," "), " pub-preview-component ")]' ] +{ #category : #accessing } +PubPub >> extractTableOfContents [ + ^ self extractRawTableOfContents collect: [:each | + PubPubContent fromXML: each + ] +] + { #category : #accessing } PubPub >> folder [ ^ folder ensureCreateDirectory diff --git a/src/MiniDocs/PubPubContent.class.st b/src/MiniDocs/PubPubContent.class.st index 4a15f67..65a975d 100644 --- a/src/MiniDocs/PubPubContent.class.st +++ b/src/MiniDocs/PubPubContent.class.st @@ -10,6 +10,11 @@ Class { #category : #'MiniDocs-Model' } +{ #category : #accessing } +PubPubContent class >> fromXML: anXMLElement [ + ^ self new fromXML: anXMLElement +] + { #category : #accessing } PubPubContent >> fromXML: aXMLElement [ | image anchor| @@ -24,7 +29,28 @@ image anchor := (aXMLElement contentNodes second contentNodes first xpath: './div[@class="title-wrapper"]/a') first. self title: (anchor attributeAt: 'title'); - url: (anchor attributeAt: 'title'). + url: (anchor attributeAt: 'href'). +] + +{ #category : #accessing } +PubPubContent >> id [ + ^ (self url splitOn: $/) last +] + +{ #category : #accessing } +PubPubContent >> printOn: aStream [ + super printOn: aStream. + aStream + nextPutAll: '( ', self title,' | ', self id, ' )' +] + +{ #category : #accessing } +PubPubContent >> shortName [ + | sanitized | + sanitized := (self title splitOn: $:) first. + sanitized := sanitized asCamelCase. + sanitized at: 1 put: sanitized first asLowercase. + ^ sanitized ] { #category : #accessing } @@ -32,11 +58,21 @@ PubPubContent >> thumbnail: anURL [ thumbnail := anURL ] +{ #category : #accessing } +PubPubContent >> title [ + ^ title +] + { #category : #accessing } PubPubContent >> title: anObject [ title := anObject ] +{ #category : #accessing } +PubPubContent >> url [ + ^url +] + { #category : #accessing } PubPubContent >> url: anObject [ url := anObject