Access (Markdown) Content files from Functions

This is a shot in the dark - but is there any workflow to accessing Hugo content files from a lambda function? The use case is having the function keep up with the latest changes to the content’s point values (each file is a unit that has an associated point value) so when that function is pinged it can return the most up to date point values for any given unit.

Should be able to connect outward to any data sources from a lambda. Just be aware that the whole transaction (receive data & startup; run code; connect to external service; receive answer; run code; return value) all needs to happen within 10 seconds so you need to make it efficient.

md files are just data, so shouldn’t be hard to access, either via https on your netlify site or a public (or private) github repo (cf https://github.com/netlify/code-examples/tree/master/function_examples/token-hider if private!), or direct API call to $remote_service_of_your_choosing…

I suspect there are some other unstated requirements, though, or you wouldn’t have asked for advice?

There aren’t necessarily unstated requirements, I’m just confused how I could access the md files through https on netlify if they don’t exist in the dist/ directory once published to the site.

If they are your data, you could only access them at their deployed paths, so you’d have to publish them :slight_smile:

Right but in another use case I want to store answers to quizzes I’m keeping in markdown files but hide those answers from the user, so I wouldn’t be displaying them in the published files in any way. So I wanted to know if I could access those markdown files from a function locally, without having to display them in a published file.

Sure, you can include static files with your function deploy, if you import them.

I’d recommend a different pattern:

  1. deploy them, unlinked but as part of your site deploy (unless your repository is open, in which case that would of course expose the content), in known paths to you.
  2. have your function download from your site while it runs, and display. This way the URL’s are hidden, info is not in any static page that a visitor could get to - in essence that data and URL’s are hidden by the “gatekeeper” function.

Sorry I did not respond sooner. For anyone else wondering, I was actually able merge all the content files into one json file using some gulp packages and then import the master file into a function which, upon build, would be bundled together, thus allowing the function to read data from all content files. This seems to align with your first solution, if I understand you correctly. I appreciate your help in finding a solution!

1 Like

awesome. thanks for sharing!