Skip to content

Commit

Permalink
Add support for broken date in metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed Jun 26, 2024
1 parent d623219 commit d71299c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 33 deletions.
29 changes: 29 additions & 0 deletions src/Microdown-Blog-Tests/MicFileTestResources.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,35 @@ MicFileTestResources >> generateFilesystemExampleEmpty [
^ file asFileReference
]

{ #category : 'fixture' }
MicFileTestResources >> generateFilesystemExampleWithBrokenDateInMetadata [

| file |
file := FileSystem memory workingDirectory / 'example1WithInvalidDate.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: '{
"title" : "Cool",
"date" : "45654765876876876876876786@@hkjhjk"
}
# A Cool Story
@sec1
Pharo is cool but _this is_ a superlong _paragraph_ Simple powerful language: No constructors, no types declaration, no interfaces, no primitive types. Yet a powerful and elegant language with a full syntax fitting in one postcard! Pharo is objects and messages all the way down. _Live_, immersive environment: Immediate feedback at any moment of your development: _Developing_, testing, debugging. Even in production environments, you will never be stuck in compiling and deploying steps again!
Amazing debugging experience: The Pharo environment includes a debugger unlike anything you''ve seen before. It allows you to step through code, restart the execution of methods, create methods on the fly, and much more!
Pharo is yours: Pharo is made by an incredible community, with more than 100 contributors for the last revision of the platform and hundreds of people contributing constantly with frameworks and libraries. Fully open-source: Pharo full stack is released under MIT License and available on GitHub
```
this is a code blu blu
```
' ].

^ file asFileReference
]

{ #category : 'fixture' }
MicFileTestResources >> generateFilesystemExampleWithoutDateInMetadata [

Expand Down
42 changes: 13 additions & 29 deletions src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,6 @@ MicSingleSummarizerTest >> createMicRootBlock [
^ micRootBlock fromFile: resources generateFilesystemExample
]

{ #category : 'fixture' }
MicSingleSummarizerTest >> generateFilesystemExampleWithBrokenDateInMetadata [

| file |
file := FileSystem memory workingDirectory / 'anExample1.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: '{
"title" : "Cool",
"date" : "45654765876876876876876786@@hkjhjk"
}
# A Cool Story
@sec1
Pharo is cool but _this is_ a superlong _paragraph_ Simple powerful language: No constructors, no types declaration, no interfaces, no primitive types. Yet a powerful and elegant language with a full syntax fitting in one postcard! Pharo is objects and messages all the way down. _Live_, immersive environment: Immediate feedback at any moment of your development: _Developing_, testing, debugging. Even in production environments, you will never be stuck in compiling and deploying steps again!
Amazing debugging experience: The Pharo environment includes a debugger unlike anything you''ve seen before. It allows you to step through code, restart the execution of methods, create methods on the fly, and much more!
Pharo is yours: Pharo is made by an incredible community, with more than 100 contributors for the last revision of the platform and hundreds of people contributing constantly with frameworks and libraries. Fully open-source: Pharo full stack is released under MIT License and available on GitHub
```
this is a code blu blu
```
' ].

^ file asFileReference
]

{ #category : 'running' }
MicSingleSummarizerTest >> setUp [

Expand Down Expand Up @@ -222,6 +193,19 @@ MicSingleSummarizerTest >> testWithMetaDataAndWithoutDate [
equals: micSingleSummarizer replacementDate
]

{ #category : 'tests' }
MicSingleSummarizerTest >> testWithMetaDataButInvalidDate [

| root |
root := micSingleSummarizer summarizeFile:
resources generateFilesystemExampleWithBrokenDateInMetadata.
self
assert: (root isKindOf: MicRootBlock);
assert: root children size equals: 3;
assert: (root children first atKey: #date)
equals: micSingleSummarizer replacementDate
]

{ #category : 'tests' }
MicSingleSummarizerTest >> testWithoutMetaData [

Expand Down
6 changes: 6 additions & 0 deletions src/Microdown-Blog/MicAbstractBlogCreator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ MicAbstractBlogCreator >> makeALink: aText to: aLink [
^ (MicInlineParser parse: '[' , text , '](' , link , ')') first
]

{ #category : 'verifying' }
MicAbstractBlogCreator >> setValidDateTo: metadata [

metadata atKey: #date put: self replacementDate
]

{ #category : 'accessing' }
MicAbstractBlogCreator >> targetDirectory [

Expand Down
12 changes: 8 additions & 4 deletions src/Microdown-Blog/MicSingleSummarizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,15 @@ MicSingleSummarizer >> verifyDateMetadata: aMicRootBlock [
ifFalse: [
metadata := MicMetaDataBlock new.
metadata body: Dictionary new.
metadata body at: #date put: self replacementDate ]
self setValidDateTo: metadata ]
ifTrue: [
metadata := aMicRootBlock children at: 1.
(metadata body includesKey: #date) ifFalse: [
metadata body at: #date put: self replacementDate ] ].
metadata := aMicRootBlock children first.
(metadata includesKey: #date)
ifFalse: [ self setValidDateTo: metadata ]
ifTrue: [
[ Date readFrom: (metadata atKey: #date) pattern: 'y/m/d' ]
on: DateError
do: [ :ex | self setValidDateTo: metadata ] ] ].
metadata parent: newMicRootBlock.

aMicRootBlock children
Expand Down

0 comments on commit d71299c

Please sign in to comment.