Passing environment variable to the yaml file header #153

Open
opened 2022-10-27 13:14:02 +00:00 by elaamrani · 2 comments
elaamrani commented 2022-10-27 13:14:02 +00:00 (Migrated from github.com)

Hello,

I would like to pass environment variables to the yaml file header. I tried the following:

---
name: ${{ process.env.ENV_VAR }}
name: `${{ process.env.ENV_VAR }}`
name: ${ENV_VAR}
name: $ENV_VAR
---

None of them worked. Would it be something possible to do?

Thanks!

Hello, I would like to pass environment variables to the yaml file header. I tried the following: ``` --- name: ${{ process.env.ENV_VAR }} name: `${{ process.env.ENV_VAR }}` name: ${ENV_VAR} name: $ENV_VAR --- ``` None of them worked. Would it be something possible to do? Thanks!
webketje commented 2023-04-25 20:39:54 +00:00 (Migrated from github.com)

Actually you can do this when running gray-matter in Node using the JS parser:

---js
{
  NODE_ENV: process.env.NODE_ENV
}
---

Alternatively you could supply a custom parser engine:

import { javascript } from 'gray-matter/lib/engines.js'

const parsed = matter(str, {
  engines: {
    'embedded-js': (str, options) => {
      // naive implementation but you get the gist
      return javascript.parse(str.replace(/\$/g, 'process.env.'), options)
    }
  }
})

Then use it like so:

---embedded-js
{
  NODE_ENV: $NODE_ENV
}
---
Actually you can do this when running gray-matter in Node using the JS parser: ```js ---js { NODE_ENV: process.env.NODE_ENV } --- ``` Alternatively you could supply a custom parser engine: ```js import { javascript } from 'gray-matter/lib/engines.js' const parsed = matter(str, { engines: { 'embedded-js': (str, options) => { // naive implementation but you get the gist return javascript.parse(str.replace(/\$/g, 'process.env.'), options) } } }) ``` Then use it like so: ```js ---embedded-js { NODE_ENV: $NODE_ENV } --- ```
YiannisBourkelis commented 2024-01-07 20:00:35 +00:00 (Migrated from github.com)

I would like to do something similar, accessing environment variables on astro docs front matter.

---
title: Page title for product name: {process.env.PUBLIC_ENV_APPNAME}
description: A description
sidebar:
  order: 3
---

Is this somehow possible using gray-matter?

I would like to do something similar, accessing environment variables on astro docs front matter. ``` --- title: Page title for product name: {process.env.PUBLIC_ENV_APPNAME} description: A description sidebar: order: 3 --- ``` Is this somehow possible using gray-matter?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rtlabs-llm-agents/gms-gray-matter#153
No description provided.