Code Monkey home page Code Monkey logo

nuxt-content-git's Introduction

nuxt-content-git

npm version Linux macOS Windows compatible Build status Coverage status Dependency status Renovate enabled
Open in Gitpod Buy Me a Coffee PayPal Patreon

Additional module for @nuxt/content that replaces or adds createdAt and updatedAt dates based on the git history.

Install

# npm
$ npx nuxi module add nuxt-content-git

# Yarn
$ yarn nuxi module add nuxt-content-git

Usage

Add the module to your nuxt.config.js:

export default {
  modules: [
    '@nuxt/content',
    'nuxt-content-git',
  },
}

This will set doc.createdAt and doc.updatedAt with the dates from the Git log.

It is also possible to not override the values but instead specify the field names like this:

export default {
  modules: [
    '@nuxt/content',
    ['nuxt-content-git', {
      createdAtName: 'gitCreatedAt',
      updatedAtName: 'gitUpdatedAt',
    }],
  ],
}

Then you can access them via doc.gitCreatedAt and doc.gitUpdatedAt.

Nuxt 2

For Nuxt 2 you need to add the module before @nuxt/content:

export default {
  modules: [
    'nuxt-content-git',
    '@nuxt/content',
  },
}

Deployment

The module uses the Git history to calculate the dates. That is why the history also needs to be checked out when deploying the project to live. During local development the repository is usually deeply cloned. But CI systems like GitHub Actions often only do a shallow clone for performance reasons, which will result in wrong dates.

To do a deep clone in a GitHub Actions workflow, configure the checkout step the following way:

- uses: actions/checkout
  with:
    fetch-depth: 0

Keep in mind that when deploying to static site hosters like GitHub Pages, you also need to do a deep clone on the system where you are generating the site. So do a local regular clone when generating locally, or use the config above for GitHub actions.

Contribute

Are you missing something or want to contribute? Feel free to file an issue or a pull request! ⚙️

Support

Hey, I am Sebastian Landwehr, a freelance web developer, and I love developing web apps and open source packages. If you want to support me so that I can keep packages up to date and build more helpful tools, you can donate here:

Buy Me a Coffee  If you want to send me a one time donation. The coffee is pretty good 😊.
PayPal  Also for one time donations if you like PayPal.
Patreon  Here you can support me regularly, which is great so I can steadily work on projects.

Thanks a lot for your support! ❤️

See also

  • nuxt-content-body-html: Embed a Mermaid diagram in a Nuxt.js app by providing its diagram string.
  • nuxt-mail: Adds email sending capability to a Nuxt.js app. Adds a server route, an injected variable, and uses nodemailer to send emails.
  • nuxt-route-meta: Adds Nuxt page data to route meta at build time.
  • nuxt-modernizr: Adds a Modernizr build to your Nuxt.js app.
  • nuxt-mermaid-string: Embed a Mermaid diagram in a Nuxt.js app by providing its diagram string.

License

MIT License © Sebastian Landwehr

nuxt-content-git's People

Contributors

actions-user avatar dword-design avatar dword-design-honestly avatar github-actions[bot] avatar renovate-bot avatar renovate[bot] avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

vernaillen

nuxt-content-git's Issues

Error when git not installed or project do not have .git at all.

If you not have git in your system (docker node:apline eg), you have this error:

[nuxt] [request error] [unhandled] [500] Error: spawn git ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:285:19)
    at onErrorNT (node:internal/child_process:483:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
  at ChildProcess._handle.onexit (node:internal/child_process:285:19)  
  at onErrorNT (node:internal/child_process:483:16)  
  at process.processTicksAndRejections (node:internal/process/task_queues:82:21)  
  at Object.action (./node_modules/simple-git/dist/esm/index.js:3824:25)  
  at PluginStore.exec (./node_modules/simple-git/dist/esm/index.js:3851:25)  
  at ./node_modules/simple-git/dist/esm/index.js:1271:43  
  at new Promise (<anonymous>)  
  at GitExecutorChain.handleTaskData (./node_modules/simple-git/dist/esm/index.js:1269:16)  
  at GitExecutorChain.<anonymous> (./node_modules/simple-git/dist/esm/index.js:1253:44)  
  at Generator.next (<anonymous>)  
  at fulfilled (./node_modules/simple-git/dist/esm/index.js:50:24)

And if you install git in your system, you got this:

[nuxt] [request error] [unhandled] [500] fatal: not a git repository (or any of the parent directories): .git

  at Object.action (./node_modules/simple-git/dist/esm/index.js:3824:25)  
  at PluginStore.exec (./node_modules/simple-git/dist/esm/index.js:3851:25)  
  at ./node_modules/simple-git/dist/esm/index.js:1271:43  
  at new Promise (<anonymous>)  
  at GitExecutorChain.handleTaskData (./node_modules/simple-git/dist/esm/index.js:1269:16)  
  at GitExecutorChain.<anonymous> (./node_modules/simple-git/dist/esm/index.js:1253:44)  
  at Generator.next (<anonymous>)  
  at fulfilled (./node_modules/simple-git/dist/esm/index.js:50:24)

May be it's not en error, but on public site you have this error while rendering <ContentList>:

{
  "message": "You should use slots with <ContentList>",
  "slot": "not-found"
}

Which represent nothing important and does not mean any error with slots.

I think plugin need handle this usecase for docker/empty .git, etc.

Warning: Permanently added the ECDSA host key for IP address

Hello,

I installed the package but when I try to use it with github action I get the following error.

Command: git
Arguments: ls-remote --tags --heads ssh://[email protected]/dword-design/dedent.git
Directory: /home/runner/work/***/***
Output:
Warning: Permanently added the ECDSA host key for IP address 'IP' to the list of known hosts.

gitCreatedAt doesnt work after deploying on gh-pages

gitCreatedAt doesnt work after deploying on github actions to gh-pages 😭
they all just end up being today's date. am i the only one struggling w/ this?
if not, please let me know how to fix the issues 😞
(and ofc i did install nuxt-content-git via npm)

this is my _slug file,

...
            <p class="text-base md:text-xl text-gray-500 text-center mb-16">
                {{formatDate(article.gitCreatedAt)}} · by
                <span v-for="memberAuthor of member" :key="memberAuthor"> 
                    <nuxt-link :to="{path: `/member/${memberAuthor.slug}`}" replace class="hover:underline">
                        {{memberAuthor.name}}
                    </nuxt-link>
                </span>
            </p>
...

this is my nuxt.config.js file,

export default {
...
  modules: [

    //https://github.com/dword-design/nuxt-content-git
    ['nuxt-content-git', {
      createdAtName : 'gitCreatedAt',
      updatedAtName : 'gitUpdatedAt',
    }],

    // https://go.nuxtjs.dev/content
    '@nuxt/content',
    '@nuxtjs/google-analytics'

  ],
...
}

and this is my yml file for auto building and deploying on github actions.

name: cd

on: [push, pull_request]

jobs:
  cd:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [ubuntu-latest]
        node: [14]

    steps:
      - name: Checkout
        uses: actions/checkout@master

      - name: Setup node env
        uses: actions/[email protected]
        with:
          node-version: ${{ matrix.node }}

      - name: Install dependencies
        run: yarn

      - name: Generate
        run: yarn run generate

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./dist

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.