Skip to content

Commit

Permalink
Merge pull request #45 from ClubCedille/feature/changeBlogToMarkdown
Browse files Browse the repository at this point in the history
converted blogs written in html to markdown
  • Loading branch information
SonOfLope authored Jan 22, 2024
2 parents 5be9116 + b5e0490 commit 8fe97bd
Show file tree
Hide file tree
Showing 209 changed files with 1,983 additions and 29,679 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
theme
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,25 @@ Nous organisons régulièrement des ateliers pour enseigner les bases du trading
## Projets en IA

Nous travaillons également sur des projets qui utilisent l'intelligence artificielle pour améliorer les algorithmes de trading et pour analyser le marché financier.

## Contribuer

Pour ajouter
une page de blog, simplement rédiger un nouveau fichier markdown sous le repertoire source/blog avec les frontmatters suivant :

```md
---
title: Votre titre
page-name: "Le nom de votre page"
background-image-url: "images/blog/lien/vers/image.jpg"
facebook-link :
twitter-link :
linkedin-link :
tags : [ "tag1", "tag2", "tag3"]
author : Nom autheur
author-title : Capitaine
author-role : Rôle
author-img : images/team/team-X.png
date : 1 janvier 2024
---
```
99 changes: 78 additions & 21 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ const fileinclude = require("gulp-file-include");
const autoprefixer = require("gulp-autoprefixer");
const bs = require("browser-sync").create();
const rimraf = require("rimraf");
const comments = require("gulp-header-comment");
const plumber = require('gulp-plumber');
const fs = require('fs');
const tap = require('gulp-tap');
const through = require('through2');
const frontMatter = require('gulp-front-matter');

async function getMarkdown() {
const markdown = await import('gulp-markdown');
return markdown.default;
}

var path = {
src: {
html: "source/*.html",
blog: "source/blog/*.html",
blog: "source/blog/*.md",
others: "source/*.+(php|ico|png)",
htminc: "source/partials/**/*.htm",
incdir: "source/partials/",
Expand All @@ -30,25 +36,67 @@ var path = {
},
};

// HTML
gulp.task("html:build", function () {
return gulp
.src(path.src.html)
.pipe(plumber({
errorHandler: function (err) {
console.error('Error in plugin "' + err.plugin + '": ' + err.message);
this.emit('end');
}
}))
let blogItemsIncludes = '';
// Blog
gulp.task("blog:build", async function () {
const markdown = await getMarkdown();
return gulp.src(path.src.blog)
.pipe(plumber())
.pipe(frontMatter())
.pipe(markdown())
.pipe(through.obj(function (file, enc, cb) {
this.push(file);
cb();
}, function (cb) {
if (this._transformState.writechunk) {
console.log('Processing file:', this._transformState.writechunk.relative);
console.log('Processing Markdown file:', this._transformState.writechunk.relative);
}
cb();
}))
.pipe(tap(function (file) {
// Read the template
const template = fs.readFileSync('source/blog/blog_template.html', 'utf8');

const frontMatterData = file.frontMatter;
const title = frontMatterData.title || 'Default Title';
const pageName = frontMatterData['page-name'] || 'Default Page Name';
const bgImageUrl = frontMatterData['background-image-url'] || 'default-image.jpg';
const author = frontMatterData['author'] || 'AlgoÉTS';
const authorTitle = frontMatterData['author-title'] || 'Club';
const authorRole = frontMatterData['author-role'] || '.';
const authorImg = frontMatterData['author-img'] || 'default-image.jpg';
const facebookLink = frontMatterData['facebook-link'] || 'https://www.facebook.com/';
const twitterLink = frontMatterData['twitter-link'] || 'https://twitter.com/';
const linkedinLink = frontMatterData['linkedin-link'] || 'https://www.linkedin.com/';
const date = frontMatterData['date'];
const tagsHtml = frontMatterData['tags'].map(tag =>
`<li class="list-inline-item"><a href="#" rel="tag">${tag}</a></li>`
).join('\n');
const link = file.basename;


blogItemsIncludes += `
@@include('blocks/blog/blog-item.htm', {"image_src": "${bgImageUrl}", "date": "${date}", "title": "${title}", "summary": "${pageName}", "link": "${link}"})
`;

// Replace placeholders in the template
const htmlContent = template
.replace(/{{ title }}/g, title)
.replace(/{{ page-name }}/g, pageName)
.replace(/{{ background-image-url }}/g, bgImageUrl)
.replace(/{{ author }}/g, author)
.replace(/{{ author-title }}/g, authorTitle)
.replace(/{{ author-role }}/g, authorRole)
.replace(/{{ author-img }}/g, authorImg)
.replace(/{{ facebook-link }}/g, facebookLink)
.replace(/{{ twitter-link }}/g, twitterLink)
.replace(/{{ linkedin-link }}/g, linkedinLink)
.replace(/{{ tags }}/g, `<ul class="list-inline">${tagsHtml}</ul>`)
.replace(/{{ content }}/g, file.contents.toString());

// Update the file content
file.contents = Buffer.from(htmlContent);
}))
.pipe(fileinclude({
basepath: path.src.incdir,
}))
Expand All @@ -57,18 +105,25 @@ gulp.task("html:build", function () {
stream: true,
}));
});

// Blog
gulp.task("blog:build", function () {
// HTML
gulp.task("html:build", function () {
return gulp
.src(path.src.blog)
.src(path.src.html)
.pipe(plumber({
errorHandler: function (err) {
console.error('Error in plugin "' + err.plugin + '": ' + err.message);
this.emit('end');
}
}))
.pipe(through.obj(function (file, enc, cb) {
// Check if the file is blog-grid.html
if (file.basename === 'blog-grid.html') {
// Replace {{ blogList }} with blogItemsIncludes
let fileContent = file.contents.toString();
fileContent = fileContent.replace('{{ blogList }}', blogItemsIncludes);
file.contents = Buffer.from(fileContent);
}

this.push(file);
cb();
}, function (cb) {
Expand All @@ -86,6 +141,9 @@ gulp.task("blog:build", function () {
}));
});

gulp.task("blog-and-html:build", gulp.series("blog:build", "html:build"));


// SCSS
gulp.task("scss:build", function () {
return gulp
Expand Down Expand Up @@ -156,6 +214,7 @@ gulp.task("clean", function (cb) {
gulp.task("watch:build", function () {
gulp.watch(path.src.html, gulp.series("html:build"));
gulp.watch(path.src.blog, gulp.series("blog:build"));
gulp.watch(path.src.blog, gulp.series("blog-and-html:build"));
gulp.watch(path.src.htminc, gulp.series("html:build"));
gulp.watch(path.src.scss, gulp.series("scss:build"));
gulp.watch(path.src.js, gulp.series("js:build"));
Expand All @@ -168,8 +227,7 @@ gulp.task(
"default",
gulp.series(
"clean",
"html:build",
"blog:build",
"blog-and-html:build",
"js:build",
"scss:build",
"images:build",
Expand All @@ -189,8 +247,7 @@ gulp.task(
gulp.task(
"build",
gulp.series(
"html:build",
"blog:build",
"blog-and-html:build",
"js:build",
"scss:build",
"images:build",
Expand Down
Loading

0 comments on commit 8fe97bd

Please sign in to comment.