Renaming and improved YAML metadata reading.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2024-03-16 12:19:31 -05:00
parent ac8fa682e3
commit d876485db9
2 changed files with 44 additions and 43 deletions

View File

@ -65,9 +65,6 @@ Markdown >> contents [
| response |
response := WriteStream on: ''.
response
nextPutAll: self class yamlMetadataDelimiter; cr;
nextPutAll: self metadataAsYAML; cr;
nextPutAll: self class yamlMetadataDelimiter; cr;
nextPutAll: self body.
^ response contents
]
@ -181,6 +178,7 @@ Markdown >> file: aFileReference [
Markdown >> fromFile: aFileReference [
self contents: aFileReference contents.
self file: aFileReference.
self populateMetadata
]
{ #category : #'instance creation' }
@ -200,6 +198,7 @@ Markdown >> gtTextFor: aView [
{ #category : #utilities }
Markdown >> lines [
self file ifNotNil: [^ self file contents lines ].
^ self contents lines.
]
@ -236,12 +235,7 @@ Markdown >> options [
{ #category : #accessing }
Markdown >> populateMetadata [
| rawMeta |
rawMeta := MiniDocs yamlToJson: self yamlMetadataString.
rawMeta associationsDo: [ :assoc |
assoc value = 'false' ifTrue: [ assoc value: false ].
assoc value = 'true' ifTrue: [ assoc value: true ] ].
self metadata: rawMeta
self metadata: (YAML2JSON fromString: self yamlMetadataString)
]
{ #category : #accessing }

View File

@ -1,5 +1,5 @@
Class {
#name : #PubPub,
#name : #PubPubWork,
#superclass : #Object,
#instVars : [
'address',
@ -13,45 +13,45 @@ Class {
}
{ #category : #accessing }
PubPub >> addTableOfContents: anOrderedDictionary [
PubPubWork >> addTableOfContents: anOrderedDictionary [
self tableOfContents
at: (self currentLanguage) put: anOrderedDictionary;
yourself
]
{ #category : #accessing }
PubPub >> addTitle: aString [
PubPubWork >> addTitle: aString [
self titles
at: (self currentLanguage) put: aString
]
{ #category : #accessing }
PubPub >> address [
PubPubWork >> address [
^ address
]
{ #category : #accessing }
PubPub >> address: anUrl [
PubPubWork >> address: anUrl [
address := anUrl
]
{ #category : #accessing }
PubPub >> currentLanguage [
PubPubWork >> currentLanguage [
^ currentLanguage
]
{ #category : #accessing }
PubPub >> currentLanguage: twoLettersInISO639_1 [
PubPubWork >> currentLanguage: twoLettersInISO639_1 [
currentLanguage := twoLettersInISO639_1
]
{ #category : #accessing }
PubPub >> defaultTitle [
PubPubWork >> defaultTitle [
^ self titles associations first value
]
{ #category : #accessing }
PubPub >> downloadContents [
PubPubWork >> downloadContents [
| workingDirectory |
workingDirectory := self folder / self currentLanguage / 'book'.
self tableOfContentsDictionary keysAndValuesDo: [ :name :chapterAddress | |currentFileName|
@ -67,54 +67,55 @@ PubPub >> downloadContents [
]
{ #category : #accessing }
PubPub >> exportMarkdeepFiles [
| markdownFiles markdeepDocs |
markdownFiles := self languageFolder allChildren select: [:file |
file basename endsWith: '.md'
].
markdeepDocs := markdownFiles collect: [:file |
(Markdeep fromMarkdownFile:file)
].
markdeepDocs do: [:each |
each fromPubPubToMarkdeep exportAsFile
].
PubPubWork >> exportToHTML [
^ self markdownFiles
collect: [ :file | Markdown new fromFile: file ].
]
{ #category : #accessing }
PubPubWork >> exportToMarkdeep [
| markdeepDocs |
markdeepDocs := self markdownFiles
collect: [ :file | Markdeep fromMarkdownFile: file ].
markdeepDocs do: [ :each | each fromPubPubToMarkdeep exportAsFile ].
^ self languageFolder
]
{ #category : #accessing }
PubPub >> extractAllContentsRaw [
PubPubWork >> extractAllContentsRaw [
^ self frontPage xpath: '//div[@class="layout-pubs-block"]'
]
{ #category : #accessing }
PubPub >> extractRawTableOfContents [
PubPubWork >> extractRawTableOfContents [
^ self extractAllContentsRaw first xpath: '//div[contains(concat(" ",normalize-space(@class)," "), " pub-preview-component ")]'
]
{ #category : #accessing }
PubPub >> folder [
PubPubWork >> folder [
^ folder ensureCreateDirectory
]
{ #category : #accessing }
PubPub >> folder: localDirectory [
PubPubWork >> folder: localDirectory [
folder := localDirectory
]
{ #category : #accessing }
PubPub >> frontPage [
PubPubWork >> frontPage [
"This should scrap contents of the book's front-page and translate them into Markdeep,
according to our templates."
^ (XMLHTMLParser on: (self address asUrl retrieveContents)) parseDocument
]
{ #category : #accessing }
PubPub >> languageFolder [
PubPubWork >> languageFolder [
^ self folder / self currentLanguage
]
{ #category : #accessing }
PubPub >> markdeepFrontPage [
PubPubWork >> markdeepFrontPage [
| frontPage markdeepIndex |
frontPage := Markdeep new.
frontPage
@ -130,7 +131,13 @@ PubPub >> markdeepFrontPage [
]
{ #category : #accessing }
PubPub >> populateTableOfContents [
PubPubWork >> markdownFiles [
^ self languageFolder allChildren
select: [ :file | file basename endsWith: '.md' ]
]
{ #category : #accessing }
PubPubWork >> populateTableOfContents [
| contentsCollection |
contentsCollection := self extractRawTableOfContents collect: [:each |
(PubPubContent fromXML: each)
@ -140,25 +147,25 @@ PubPub >> populateTableOfContents [
]
{ #category : #accessing }
PubPub >> printOn: aStream [
PubPubWork >> printOn: aStream [
super printOn: aStream.
aStream
nextPutAll: '(',self defaultTitle, ' | ', self address, ' )'
]
{ #category : #accessing }
PubPub >> tableOfContents [
tableOfContents ifNil: [^ tableOfContents := Dictionary new].
PubPubWork >> tableOfContents [
tableOfContents ifNil: [ ^ tableOfContents := Dictionary new].
^ tableOfContents at: self currentLanguage
]
{ #category : #accessing }
PubPub >> tableOfContents: anObject [
PubPubWork >> tableOfContents: anObject [
tableOfContents := anObject
]
{ #category : #accessing }
PubPub >> tableOfContentsDictionary [
PubPubWork >> tableOfContentsDictionary [
| response |
response := OrderedDictionary new.
self tableOfContents do: [:content |
@ -169,6 +176,6 @@ PubPub >> tableOfContentsDictionary [
]
{ #category : #accessing }
PubPub >> titles [
PubPubWork >> titles [
^ titles ifNil: [titles := OrderedDictionary new]
]