Skip to content

Commit a87a8ce

Browse files
authored
Merge pull request #2 from Romelium/source-content
feat: add ability to use source as content
2 parents d21eaa8 + 69030fd commit a87a8ce

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,41 @@ That's all! The timeline block will automatically be processed, and each section
3131

3232
### A Bit More
3333

34+
#### Block Content
35+
36+
You can either format it this way, where the timeline block renders content using the text outside the block:
37+
38+
````md
39+
Today. Slow breakfast. Organized, felt good. Watched a space doc, had veggies and quinoa.
40+
41+
Tomorrow. Quick jog. Worked on a project. Dinner with friends.
42+
43+
Dec 31. Walked, reflected. Last-minute shopping. Celebrated with friends.
44+
45+
Jan 1. Slept in, journaled. Walked, read. Quiet night, healthy meal, episodes.
46+
47+
Jan 2. Made a plan. Caught up on emails, watched snow. Tried chili, read.
48+
49+
```timeline
50+
```
51+
````
52+
53+
Or, you can format it this way, by placing the content inside the block. However, this approach does not allow you to use [explicit settings](#customizing-the-source-block):
54+
55+
````md
56+
```timeline
57+
Today. Slow breakfast. Organized, felt good. Watched a space doc, had veggies and quinoa.
58+
59+
Tomorrow. Quick jog. Worked on a project. Dinner with friends.
60+
61+
Dec 31. Walked, reflected. Last-minute shopping. Celebrated with friends.
62+
63+
Jan 1. Slept in, journaled. Walked, read. Quiet night, healthy meal, episodes.
64+
65+
Jan 2. Made a plan. Caught up on emails, watched snow. Tried chili, read.
66+
```
67+
````
68+
3469
#### Dates
3570

3671
Each section's date is determined by the first valid date mentioned in the section. You can use various formats supported by [Chronos](https://github.com/wanasit/chrono), including:

main.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,22 @@ export default class EasyTimelinePlugin extends Plugin {
9696
// Read file content
9797
const text = await this.app.vault.read(file);
9898

99-
// Remove frontmatter and source block from file content
100-
let { contentStart } = getFrontMatterInfo(text);
101-
const sourceBlock = "```" + language + "\n" + source + "\n```";
102-
const content = text.slice(contentStart).replace(sourceBlock, '');
103-
10499
// Get and process all metadata from source block
105100
const metadata = extractVariedMetadata(source);
106101
const metadataReference = metadata.reference ? strict.parseDate(metadata.reference) : null;
107102
const metadataSort = metadata.sort ? { ascending: 'asc', descending: 'desc' }[metadata.sort.toLowerCase()] || metadata.sort : null;
108103
const sort = ((metadataSort === 'asc' || metadataSort === 'desc') ? metadataSort : this.settings.sort);
109104

105+
// Remove frontmatter and source block from file content
106+
let { contentStart } = getFrontMatterInfo(text);
107+
const sourceBlock = "```" + language + "\n" + source + "\n```";
108+
const content = source.length != 0 && Object.keys(metadata).length === 0 ? source : text;
109+
110110
// find reference date in content
111111
const reference = metadataReference ?? (await this.findReference(file));
112112

113113
// Get timeline object representation
114-
const timeline = content
114+
const timeline = content.slice(contentStart).replace(sourceBlock, '')
115115
.split(this.settings.singleLine ? '\n' : '\n\n') // Split content into lines and process dates for each lines
116116
.map(line => {
117117
return {
@@ -122,7 +122,7 @@ export default class EasyTimelinePlugin extends Plugin {
122122
.filter(value => value.date != null) as TimelineData // Don't include lines with no valid dates
123123

124124
// Render timeline
125-
const timelineEl = renderTimeline(timeline, sort as "asc" | "desc", );
125+
const timelineEl = renderTimeline(timeline, sort as "asc" | "desc",);
126126
el.replaceWith(timelineEl)
127127
});
128128
}

0 commit comments

Comments
 (0)