Code Monkey home page Code Monkey logo

markdown-blog's Introduction

Markdown Blog

Extremly simple "static" PHP blog that renders markdown posts. No installation or database needed.

To create a post just write a new .md file. Everything else just works.

Note: It's not a full blogging platform, does not currently come with any premade themes, it's just a script and specific folder structure to load and display markdown files.

Demo

You can see a usage demo here (the blog is integrated into an existing site).

Why?

You already have a site and want to integrate a blog within it. I asked others for recommendations, but most suggestions involved some complex stand-alone blogging platform or service.
I just wanted a simple way to create and display blog posts on my existing site.

Solution

The solution came together by combining several suggestions received in the post mentioned above with some of my own ideas:

  • Write blog posts in Markdown.
  • Preview Markdown while typing directly in VSCode. vscode-image-preview
  • Use a PHP Markdown parsing library to load the .md files on the fly. I used Parsedown. This means that no database is needed, there is no build step and you can easily version posts using git.
  • Use .htaccess rewrites for nice blog post URLs.

Requirements

  • PHP 5.4+
  • Apache (or other .htaccess compatible web server)

Installation

Copy the markdown-blog folder to a PHP server.
You can also change the name of the folder, normally you would name it blog so you can access it like yoursite.com/blog.

Usage

You can create new posts by adding new post-url-slug.md files in the posts folder. The post must start with a # Heading, which will also be the title of the post and used in the <title> tag.

Customization

The advantage of having something simple like this is that it's really easy to customize.

There are not really any default styles, as this is meant to be includded on your own site, which means it will inherit the CSS of your site. If you want better Markdown styling you can search for existing Markdown themes.

You can add your own HTML or CSS wherever you want. In the demo example I just added the header.php and footer.php that I use on the other pages of my static site.

The md-styles.css is just used to stylize the Markdown preview in Visual Studio Code. You can safely remove it, but having one means that you can preview your blog post in VSCode with the exact styles as on your site.

Wait, but it uses PHP, why do you call it "static"?

You are right! It's not static as in just plain HTML served from a server. But if you think about it, even a plain HTML site is hosted on a server which dynamically responds to HTTP requests.

I personally still consider it to be "static" because:

  • I use Cloudflare on top of it with cache everything option, so requests do not reach my server, Cloudflare always responds with plain HTML/CSS, without executing the dynamic PHP code that processes the markdown.
  • The servers that the client reaches are the Cloudflare servers, where the static assets are indeed served directly as-is.
  • Content is written in a static file and doesn't change between requests.
  • There is no database or content generated based on dynamic data (the only dynamic part is the URL, but it always points to the file name, the same as with static sites).
  • There is no build step. If it's needed you can easily add a build step that simply saves the generated HTML output, thus making it truly satic. But now Cloudflare is already doing this.

What exactly makes a website "static"?

Changelog

20 March 2024

  • ⚠️Security: Fix XSS issue with 404 posts. Thanks to @Pinky for the report.
  • ⚠️Security: Fix potential path traversal issue with 404 posts.
  • Add 404 Not Found HTTP header to 404 posts (for better SEO and user experience).

20 Nov 2023

  • Display post creation date in blog posts list
  • Add ability to sort the blog posts list (default: newest first — sort descending by file creation date)

8 March 2021

  • Added automatic generation of RSS feed. By default it can be accessed at /blog/rss.php
  • Added settings.php file, holds basic configuration options and RSS channel details.
  • Added some helper function to getPostsList (used in rendering posts and RSS feed).
  • A few codebase improvements.

License

MIT

Check out my analytics script

This is the app for which I needed and created this blog project:
Self-hosted analytics UXWizz
Self-hosted analytics plaform with heatmaps and full session recordings.

markdown-blog's People

Contributors

crishnakh avatar cristy94 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

markdown-blog's Issues

function getFirstLines doesn’t seems to works

Hi, as the title says, the function getFirstLines does not work in my test folder, with windows and PHP 8.1.

The blog post list render the full lenght of the markdown page :

image

I see here that PHP_EOL is behaving differently depending on if we are on a unix-based system or a windows one, maybe it’s where the problem is ?
Do you have any idea how to correct the problem ? I’m not a dev so it’s a bit hard for me, but I will try some things, it would be cool to be able to use your project !

sorting and displaying the date

Hi, the only functions who are lacking in my opinion are a way to choose the sorting of the blog post (it appears to be alphabetical (? - in the demo you doesn’t seem to have an alphabetical sorting ?), so if I name a .md post with the date, the posts will appear chronologically and not ante-chronologically, wich would be better. I also would like to display a date of the post.

How would you do the sorting ?

For displaying the date, in the RSS you seems to use $post["create_date"] but it may be a wrong date for the real posting date 🤔

Error on Blog post page

Hey, I love the minimalistic blog thing !!

I'm trying to intregrate it in my own website. But...

When I go to the blog post page, i gives me a Object not found! error...

2021-11-17_16-36

Mind telling me what I'm doing wrong ?

Adding a docker file to run the project

In case you're interested in adding this:

$ cat Dockerfile 
FROM php:7.2-apache
COPY markdown-blog/ /var/www/html/
RUN a2enmod rewrite
RUN echo "RewriteEngine On" >> /etc/apache2/apache2.conf

Then:

docker build -t my-php-app .
docker run -it -p 80:80 my-php-app

PHP docker docs: https://hub.docker.com/_/php

Been shopping around for blog stuff and came on to your project. I like it! Hope you find this helpful. Could be a good way to advertise it for users who are interested in trying it out but not too familiar with PHP.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.