Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: frontmatter.js configuration #553

Closed
davidsneighbour opened this issue Mar 29, 2023 · 4 comments
Closed

Enhancement: frontmatter.js configuration #553

davidsneighbour opened this issue Mar 29, 2023 · 4 comments

Comments

@davidsneighbour
Copy link
Contributor

This would be a "nice to have" feature. Enabling us to have some Javascript create a configuration object that is then exported.

Use case: My local development server (preview server) has changing IP addresses and ports depending on the machine they run on. Having IP and port configuration in .env and then the javascript retrieve that via dotenv to create "frontMatter.preview.host": "http://192.168.1.201:1313" would increase the portability of the configuration.

Something like this:

require('dotenv').config(); // load environment variables from .env file

const envvars = {
  ip: process.env.IP_ADDRESS || '127.0.0.1', // use IP address from environment variable or default to localhost
  port: process.env.PORT || 3000 // use port from environment variable or default to 3000
};

const config = {
  // other configs
  "frontMatter.preview.host": "https://" + envvars.ip + ":" + envvars.port
  // other configs
}

module.exports = config;

I am not sure in how far this breaks the concept of extensions inside .frontmatter folders, but this would be only for the frontmatter.json file in the root of the project.

@davidsneighbour davidsneighbour added the enhancement New feature or request label Mar 29, 2023
@estruyf
Copy link
Owner

estruyf commented Mar 29, 2023

Thanks @davidsneighbour for the suggestion, have to look at it and do some testing to see how easy/difficult this would be to implement.

@estruyf
Copy link
Owner

estruyf commented Sep 18, 2023

@davidsneighbour, I have been thinking of it but haven't found a way yet to make it work.

@estruyf
Copy link
Owner

estruyf commented Sep 18, 2023

I found a way; it was a problem in webpack, and I can make these dynamic imports work.

I think the approach will be the following:

  • Adding a new setting frontMatter.config.dynamicFilePath
  • When the setting is present, it will be loaded and used after FM processed the settings

I have done the following test:

const path = require('path');
const uuid = require('uuid');
require('dotenv').config({
  path: path.join(__dirname, `.env`)
});

module.exports = async (config) => {
  return {
    ...config,
    test: process.env.TESTING,
    dir: __dirname,
    id: uuid.v4(),
  }
}; 

FM receives the config + the additional values.

Xnapper-2023-09-18-16 24 55

The reason you need to add path.join(__dirname, '.env') is that it would otherwise run within the extension folder.

estruyf added a commit that referenced this issue Sep 18, 2023
@estruyf
Copy link
Owner

estruyf commented Sep 18, 2023

You'll be able to test it out in the upcoming beta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants