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

View File

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