This directory contains the Netlify functions and plugins used by the site. Here’s a breakdown of the directory structure:
netlify/
├── functions/
│ └── hello.js # Example serverless function
│
└── plugins/
└── jobs-structured-schema-api/
├── manifest.yml # Plugin manifest file (required)
└── netlify-plugin-jobs-structured-schema-api.js # Plugin code (required)
The functions
subdirectory contains serverless function files. Currently, it includes the following file:
hello.js
: A temporary/example serverless function file.hello.js
exports.handler = async function (event, context) {
return {
statusCode: 200,
body: JSON.stringify({ message: "Hello UX Brighton!" }),
};
};
The plugins
subdirectory contains Netlify plugins. Currently, it includes the following plugin:
jobs-structured-schema-api
: A plugin for processing job post markdown files and adding structured data to the content pulled from an external API.jobs-structured-schema-api
The plugin includes the following files:
manifest.yml
: The manifest file for the plugin — (This file is required for all Netlify plugins.)netlify-plugin-jobs-structured-schema-api.js
: The plugin script file responsible for processing job post markdown files — (This file is required for all Netlify plugins.)The plugin performs the following tasks:
NOTE: The updated markdown files only appear in the Nelify deploy preview and not in the local repository. This is because the plugin is executed during the build process and the updated files are not committed to the repository.
netlify-plugin-jobs-structured-schema-api.js
// Dependencies
const axios = require('axios');
const fs = require('fs-extra');
const path = require('path');
module.exports = {
async onPreBuild() {
// Code for processing job post markdown files
// ...
},
};
// Helper functions
// ...
The netlify-plugin-jobs-structured-schema-api.js
file also includes several helper functions used in the processing of job post markdown files:
extractJsonFrontMatter(content)
: Extracts the JSON front matter and content from a markdown file.createMarkdownWithJsonFrontMatter(jsonFrontmatter, content)
: Updates the JSON front matter in the content and returns the updated markdown content.appendToBody(content, data)
: Appends the provided JSON data as a <script>
tag to the body area of the markdown content.To utilise the jobs-structured-schema-api
plugin in your Netlify project, follow these steps:
Add the plugin to your netlify.toml
file:
[[plugins]]
package = "netlify-plugin-jobs-structured-schema-api"
Ensure that the jobs-structured-schema-api
plugin directory is present within the plugins
directory of your Netlify project.
Customize the plugin’s behavior by modifying the netlify-plugin-jobs-structured-schema-api.js
file as needed. You can adjust the API endpoint, token retrieval, or any other relevant logic within the onPreBuild
method.
Run the Netlify build command to trigger the plugin’s execution during the build process.
Example command: netlify build