-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
Issue: Image preview on dashboard cards works only sporadically #908
Comments
Thanks @davidsneighbour, happy new year for you too. I'll have a look at it. |
@davidsneighbour, the As there are multiple content types defined for your blog in the Here is the view of your articles when I added |
Ok, that makes sense, ... "but" ;) It also messes up the last modified stamps on all content (if I add it now) ;) Not complaining, just asking. |
At this moment, yes, that is indeed the case. Or have a
Each SSG has its own implementation. That is why FM uses the
To temporarily turn this off, you can set the |
Got it. For convenience sake, here is a little NodeJS script for anyone who got to change many markdown files in a folder. This one does what I did not want to do by hand (traverse through a directory and add/change one front matter value in every markdown file) ;) #!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
// Function to show help message
const showHelp = () => {
console.log(`
Usage:
node manage-frontmatter.mjs --folder=content --key=PARAM --value=NEWVALUE
Options:
--folder=<path> Directory to scan for Markdown files (default: 'content')
--key=<param> Frontmatter key to add/update
--value=<value> New value for the frontmatter key
--help Show this help message
Examples:
node manage-frontmatter.mjs --folder=content/blog --key=fmContentType --value=blog
node manage-frontmatter.mjs --key=author --value="John Doe"
`);
process.exit(0);
};
// Parse CLI arguments
const args = process.argv.slice(2).reduce((acc, arg) => {
const [key, value] = arg.split('=');
acc[key.replace('--', '')] = value;
return acc;
}, {});
// Show help if `--help` is passed or if no required parameters are given
if (args.help || !args.key || !args.value) {
showHelp();
}
const baseFolder = args.folder || 'content';
const keyToUpdate = args.key;
const newValue = args.value;
// Function to check if a package is installed
const isPackageInstalled = async (packageName) => {
try {
await import(packageName);
return true;
} catch (e) {
return false;
}
};
// Ensure gray-matter is installed
const packageName = 'gray-matter';
isPackageInstalled(packageName).then(async (installed) => {
if (!installed) {
console.error(`\n⚠️ The package '${packageName}' is not installed.\n`);
process.stdout.write("Would you like to install it now? (y/n) ");
process.stdin.setEncoding('utf8');
process.stdin.once('data', (answer) => {
answer = answer.trim().toLowerCase();
if (answer === 'y') {
console.log(`\nInstalling ${packageName}...\n`);
try {
execSync(`npm install ${packageName}`, { stdio: 'inherit' });
console.log(`\n✅ ${packageName} installed. Please run the script again.\n`);
} catch (err) {
console.error(`\n❌ Failed to install ${packageName}. Exiting.\n`);
}
} else {
console.log(`\n❌ ${packageName} is required to run this script. Exiting.\n`);
}
process.exit();
});
process.stdin.resume();
} else {
const { default: matter } = await import(packageName);
/**
* Recursively traverses directories and updates Markdown frontmatter
* @param {string} dir - Directory to start traversal
*/
const processDirectory = (dir) => {
fs.readdirSync(dir).forEach(file => {
const fullPath = path.join(dir, file);
if (fs.statSync(fullPath).isDirectory()) {
processDirectory(fullPath);
} else if (file.endsWith('.md')) {
updateFrontmatter(fullPath);
}
});
};
/**
* Reads a markdown file, updates its frontmatter, and saves changes.
* @param {string} filePath - Path to the markdown file
*/
const updateFrontmatter = (filePath) => {
const content = fs.readFileSync(filePath, 'utf8');
const parsed = matter(content);
// Update the given key with the new value
parsed.data[keyToUpdate] = newValue;
// Convert back to markdown format
const updatedContent = matter.stringify(parsed.content, parsed.data);
fs.writeFileSync(filePath, updatedContent, 'utf8');
console.log(`Updated ${filePath}: Set '${keyToUpdate}' to '${newValue}'`);
};
// Start processing
console.log(`Scanning folder: ${baseFolder}`);
processDirectory(baseFolder);
console.log('Update complete.');
}
}); call it like this and follow the instructions: node manage-frontmatter.mjs # or, for instance
node manage-frontmatter.mjs --folder=content/blog --key=fmContentType --value=blog |
@davidsneighbour, thank you for sharing your script 🙏 |
Happy New Year ;)
Describe the bug
The image preview works only in some of my recent posts. I wonder if it has to do with my schema or some other frontmatter quirks. The images linked are available and (to my eyes) are identical configured in the frontmatter.
To Reproduce
Steps to reproduce the behavior:
npm install
Expected behavior
I would expect all three posts to have image previews
Device:
The text was updated successfully, but these errors were encountered: