-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
9df6d15
commit 1ee1989
Showing
7 changed files
with
229 additions
and
35 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 |
---|---|---|
@@ -1,16 +1,39 @@ | ||
import { addServerPlugin, createResolver, defineNuxtModule } from '@nuxt/kit' | ||
import { | ||
addServerPlugin, | ||
createResolver, | ||
isNuxt3 as isNuxt3Try, | ||
} from '@nuxt/kit' | ||
import P from 'path' | ||
|
||
import setVariables from './set-variables.js' | ||
|
||
const resolver = createResolver(import.meta.url) | ||
|
||
export default defineNuxtModule({ | ||
setup: (options, nuxt) => { | ||
nuxt.options.runtimeConfig.nuxtContentGit = { | ||
createdAtName: 'createdAt', | ||
updatedAtName: 'updatedAt', | ||
...nuxt.options.runtimeConfig.nuxtContentGit, | ||
...nuxt.options.nuxtContentGit, | ||
...options, | ||
} | ||
export default function (options, nuxt) { | ||
let isNuxt3 = true | ||
try { | ||
isNuxt3 = isNuxt3Try() | ||
} catch { | ||
isNuxt3 = false | ||
} | ||
nuxt = nuxt || this | ||
options = { | ||
createdAtName: 'createdAt', | ||
updatedAtName: 'updatedAt', | ||
...(isNuxt3 && nuxt.options.runtimeConfig.nuxtContentGit), | ||
...nuxt.options.nuxtContentGit, | ||
...options, | ||
} | ||
if (isNuxt3) { | ||
nuxt.options.runtimeConfig.nuxtContentGit = options | ||
addServerPlugin(resolver.resolve('./server-plugin.js')) | ||
}, | ||
}) | ||
} else { | ||
this.nuxt.hook('content:file:beforeInsert', (file, database) => | ||
setVariables( | ||
file, | ||
P.join(database.dir, `${file.path}${file.extension}`), | ||
options, | ||
), | ||
) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,20 +1,15 @@ | ||
import { last } from '@dword-design/functions' | ||
import P from 'path' | ||
import simpleGit from 'simple-git' | ||
|
||
import { defineNitroPlugin, useRuntimeConfig } from '#imports' | ||
|
||
export default defineNitroPlugin(nitroApp => { | ||
const options = useRuntimeConfig().nuxtContentGit | ||
nitroApp.hooks.hook('content:file:afterParse', async file => { | ||
const git = simpleGit() | ||
import setVariables from './set-variables.js' | ||
|
||
const log = await git.log({ | ||
file: P.join('content', file._file), | ||
}) | ||
file[options.createdAtName] = | ||
log.all.length > 0 ? new Date(last(log.all).date) : undefined | ||
file[options.updatedAtName] = | ||
log.latest === null ? undefined : new Date(log.latest.date) | ||
}) | ||
}) | ||
export default defineNitroPlugin(nitroApp => | ||
nitroApp.hooks.hook('content:file:afterParse', file => | ||
setVariables( | ||
file, | ||
P.join('content', file._file), | ||
useRuntimeConfig().nuxtContentGit, | ||
), | ||
), | ||
) |
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,14 @@ | ||
import { last } from '@dword-design/functions' | ||
import simpleGit from 'simple-git' | ||
|
||
export default async (file, path, options) => { | ||
const git = simpleGit() | ||
|
||
const log = await git.log({ | ||
file: path, | ||
}) | ||
file[options.createdAtName] = | ||
log.all.length > 0 ? new Date(last(log.all).date) : file.createdAt | ||
file[options.updatedAtName] = | ||
log.latest === null ? file.updatedAt : new Date(log.latest.date) | ||
} |
Oops, something went wrong.