Skip to content

Commit

Permalink
Merge pull request #16 from bhavik001/seo-meta-tags
Browse files Browse the repository at this point in the history
Update files for adding SEO feature
  • Loading branch information
bhavik001 committed Nov 2, 2023
2 parents 7358c13 + 4af653e commit 20e97d7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 47 deletions.
13 changes: 10 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ function clearOutputDir(outputDirectory) {
// The main function that performs the core functionality of the tool
function main() {
const version = getVersion();

// Define SEO metadata for the file
const metadata = {
title: "Hello Everyone",
description: "Meta tag file",
keywords: "conversion, text, markdown",
};
// Parse command-line arguments using Yargs
const argv = yargs
.option("output", {
Expand Down Expand Up @@ -78,19 +85,19 @@ function main() {
// Create output directory if it doesn't exist (with recursive option)
fs.mkdirSync(outputDirectory, { recursive: true });

processFolder(inputFilePath, outputDirectory); // Process all text files in the directory
processFolder(inputFilePath, outputDirectory, metadata); // Process all text files in the directory
console.log(
`Text files inside the directory are converted into HTML files.`
);
} else if (inputFilePath.endsWith(".txt")) {
// If the input is a .txt file, convert it to an HTML file
processTextFile(inputFilePath, outputDirectory);
processTextFile(inputFilePath, outputDirectory, metadata);
console.log(
`The Text file "${inputFilePath}" is converted into an HTML file.`
);
} else if (inputFilePath.endsWith(".md")) {
// If the input is a .md file, convert it to an HTML file
processMdFile(inputFilePath, outputDirectory);
processMdFile(inputFilePath, outputDirectory, metadata);
console.log(
`The md file "${inputFilePath}" is converted into an HTML file.`
);
Expand Down
86 changes: 42 additions & 44 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const mkdirp = require("mkdirp"); // Import the mkdirp library for creating dire
* @param {string} inputFilePath - The path to the input text file.
* @param {string} outputDirectory - The directory where the HTML output file will be saved.
*/
function processTextFile(inputFilePath, outputDirectory) {
function processTextFile(inputFilePath, outputDirectory, metadata = {}) {
// Read the content of the input text file
const inputFileContent = fs.readFileSync(inputFilePath, "utf-8");

Expand All @@ -29,27 +29,26 @@ function processTextFile(inputFilePath, outputDirectory) {

// Generate the HTML content with the extracted paragraphs
const htmlContent = `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>${fileName}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Your page description here for SEO">
<meta name="keywords" content="your, keywords, here, for, SEO">
<meta property="og:title" content="${fileName}">
<meta property="og:description" content="Your Open Graph description for social sharing">
<!-- Add more meta tags as needed for SEO -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9"
crossorigin="anonymous">
</head>
<body>
<center>
${paragraphs.map((paragraph) => `<p>${paragraph}</p>`).join("\n")}
</center>
</body>
</html>`;
<html lang="en">
<head>
<meta charset="utf-8">
<title>${metadata.title || fileName}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="${
metadata.description || "Default description"
}">
<meta name="keywords" content="${metadata.keywords || "Default, keywords"}">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9"
crossorigin="anonymous">
</head>
<body>
<center>
${paragraphs.map((paragraph) => `<p>${paragraph}</p>`).join("\n")}
</center>
</body>
</html>`;

// Write the HTML content to the output file
fs.writeFileSync(outputFile, htmlContent);
Expand Down Expand Up @@ -80,7 +79,7 @@ function processFolder(inputDir, outputDirectory) {
}
}

function processMdFile(inputFilePath, outputDirectory) {
function processMdFile(inputFilePath, outputDirectory, metadata = {}) {
const inputFileContent = fs.readFileSync(inputFilePath, "utf-8");

const paragraphs = inputFileContent
Expand All @@ -100,27 +99,26 @@ function processMdFile(inputFilePath, outputDirectory) {

// Generate the HTML content with the extracted paragraphs
const htmlContent = `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>${fileName}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Your page description here for SEO">
<meta name="keywords" content="your, keywords, here, for, SEO">
<meta property="og:title" content="${fileName}">
<meta property="og:description" content="Your Open Graph description for social sharing">
<!-- Add more meta tags as needed for SEO -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9"
crossorigin="anonymous">
</head>
<body>
<center>
${paragraphs}
</center>
</body>
</html>`;
<html lang="en">
<head>
<meta charset="utf-8">
<title>${metadata.title || fileName}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="${
metadata.description || "Default description"
}">
<meta name="keywords" content="${metadata.keywords || "Default, keywords"}">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9"
crossorigin="anonymous">
</head>
<body>
<center>
${paragraphs}
</center>
</body>
</html>`;

fs.writeFileSync(outputFile, htmlContent);
}
Expand Down

0 comments on commit 20e97d7

Please sign in to comment.