mirror of
https://github.com/bpatrik/pigallery2.git
synced 2024-12-25 02:04:15 +02:00
Improve blog inlining if no date was added #711
This commit is contained in:
parent
c81428ade1
commit
e85fa29672
@ -83,10 +83,10 @@ Start numbering with offset:
|
||||
57. foo
|
||||
1. bar
|
||||
|
||||
<!-- @pg-date 2015-06-12 -->
|
||||
<!-- @pg-date 2015-06-29 -->
|
||||
## Day 1
|
||||
|
||||
You can tag section in the `*.md` files with `<!-- @pg-date <ISO_DATE> -->`, like: `<!-- @pg-date 2015-06-12 -->` to attach them to a date.
|
||||
You can tag section in the `*.md` files with `<!-- @pg-date <ISO_DATE> -->`, like: `<!-- @pg-date 2015-06-29 -->` to attach them to a date.
|
||||
Then, if you group by date, they will show up at the assigned day.
|
||||
|
||||
That part of the markdown will be removed from the main markdown at the top and shown only at that day.
|
||||
|
@ -45,10 +45,12 @@ export class BlogService {
|
||||
return [];
|
||||
}
|
||||
|
||||
// there is no date group by
|
||||
if (dates.length == 0) {
|
||||
return [{
|
||||
text: markdown,
|
||||
file: file,
|
||||
date: null,
|
||||
textShort: markdown.substring(0, 200)
|
||||
}];
|
||||
}
|
||||
@ -61,15 +63,8 @@ export class BlogService {
|
||||
const ret: GroupedMarkdown[] = [];
|
||||
const matches = Array.from(markdown.matchAll(splitterRgx));
|
||||
|
||||
if (matches.length == 0) {
|
||||
return [{
|
||||
text: markdown,
|
||||
file: file,
|
||||
textShort: markdown.substring(0, 200)
|
||||
}];
|
||||
}
|
||||
|
||||
const getDateGroup = (dateNum: number) => {
|
||||
const getDateGroup = (date: Date) => {
|
||||
const dateNum = Utils.makeUTCMidnight(date).getTime();
|
||||
let groupDate = dates.find((d, i) => i > dates.length - 1 ? false : dates[i + 1] > dateNum); //dates are sorted
|
||||
|
||||
// cant find the date. put to the last group (as it was later)
|
||||
@ -80,6 +75,16 @@ export class BlogService {
|
||||
};
|
||||
|
||||
|
||||
if (matches.length == 0) {
|
||||
return [{
|
||||
text: markdown,
|
||||
file: file,
|
||||
textShort: markdown.substring(0, 200),
|
||||
date: getDateGroup(new Date(file.date))
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
const baseText = markdown.substring(0, matches[0].index).trim();
|
||||
|
||||
// don't show empty
|
||||
@ -87,13 +92,14 @@ export class BlogService {
|
||||
if (file.date === firstMedia) {
|
||||
ret.push({
|
||||
text: baseText,
|
||||
file: file
|
||||
file: file,
|
||||
date: null
|
||||
});
|
||||
} else {
|
||||
ret.push({
|
||||
text: baseText,
|
||||
file: file,
|
||||
date: getDateGroup(file.date)
|
||||
date: getDateGroup(new Date(file.date))
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -101,7 +107,7 @@ export class BlogService {
|
||||
for (let i = 0; i < matches.length; ++i) {
|
||||
const matchedStr = matches[i][0];
|
||||
// get UTC midnight date
|
||||
const dateNum = Utils.makeUTCMidnight(new Date(matchedStr.match(dateRgx)[0])).getTime();
|
||||
const dateNum = new Date(matchedStr.match(dateRgx)[0]);
|
||||
|
||||
const groupDate = getDateGroup(dateNum);
|
||||
|
||||
@ -148,7 +154,7 @@ export class BlogService {
|
||||
|
||||
|
||||
export interface GroupedMarkdown {
|
||||
date?: number;
|
||||
date: number | null;
|
||||
text: string;
|
||||
textShort?: string;
|
||||
file: FileDTO;
|
||||
|
Loading…
Reference in New Issue
Block a user