-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8741f3
commit 79e3887
Showing
6 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { execSync } from "node:child_process"; | ||
import path from "node:path"; | ||
|
||
import type { Root } from "mdast"; | ||
import type { Plugin } from "unified"; | ||
|
||
import { isDraft } from "./utils"; | ||
|
||
type RemarkPlugin<PluginParameters extends any[] = any[]> = Plugin< | ||
PluginParameters, | ||
Root | ||
>; | ||
|
||
export function gitCommitRemarkPlugin(): RemarkPlugin { | ||
return (_tree, file) => { | ||
const filepath = file.history[0].replace(process.cwd(), "").slice(1); | ||
const draft = isDraft(filepath); | ||
|
||
if (draft) { | ||
file.data.astro.frontmatter.commit = "<draft>"; | ||
return; | ||
} | ||
|
||
const commit = execSync(`git log -n 1 --pretty=format:%h -- ${path}`) | ||
.toString() | ||
.trim(); | ||
|
||
file.data.astro.frontmatter.commit = commit; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters