Skip to content

Instantly share code, notes, and snippets.

@webrobert
Last active December 4, 2022 23:12
Show Gist options
  • Save webrobert/39bd711ed3cc1d7081af8257f75edb96 to your computer and use it in GitHub Desktop.
Save webrobert/39bd711ed3cc1d7081af8257f75edb96 to your computer and use it in GitHub Desktop.
A markdown driven Legal pages for my Laravel sites.

A markdown driven Legal pages for my Laravel sites.

I wanted a way to easily edit legal pages. Markdown seemed to be the fastest. Turns out, Automattic agrees. Below is an example of their markdown Terms of service.

My usage is straight-forward, name your routes to match the names of the markdown files. The controller loads the file and parses it using laravels build in markdown parser. And here is a markdown cheatcheat https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet

Usage

  1. web routes for any legal pages...
Route::get('/privacy', LegalController::class)
        ->name('privacy-policy');

Route::get('/terms', LegalController::class)
        ->name('terms-of-service');

Route::get('/cookies', LegalController::class)
        ->name('cookie-policy');
  1. match the markdown file names to route names...
resources\views\legal
  markdown
    cookie-policy.md
    privacy-policy.md
    terms-of-service.md
  index.blade.php
  1. The blade file 'resources/views/legal/index.blade' uses tailwind prose to style the markup.
<x-app-layout>
<x-slot:title>{{ $name }}</x-slot>
<div class="flex items-top justify-center py-4 sm:pt-0 bg-blue-200">
<div class="prose max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8
prose-a:text-blue-600 hover:prose-a:text-blue-500
prose-h1:font-normal prose-h1:mb-0
prose-hr:max-w-sm prose-hr:my-4">
{!! $content !!}
</div>
</div>
</x-app-layout>
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Route;
use Illuminate\Mail\Markdown;
use Illuminate\Support\Str;
use Illuminate\View\View;
class LegalController extends Controller
{
private string $fileName;
public function __invoke() : View
{
$this->fileName = Route::currentRouteName();
return view('legal.index', [
'name' => Str::of($this->fileName)->title()->replace('-', ''),
'content' => $this->loadMarkdownFile()
]);
}
private function loadMarkdownFile() : String
{
try {
$pathToFile = base_path("resources/views/legal/markdown/{$this->fileName}.md");
$csvFile = fopen($pathToFile, "r");
return Markdown::parse( fread($csvFile, filesize($pathToFile)) );
} catch (\Exception ) {
abort(404);
}
// todo: add caching?
}
}

Sample bit of the Automattic Terms of Service


Last Updated: July 5, 2022

The Gist

We (the folks at Automattic) are on a mission to make the web a better place. We hope you love our products and services — from website publishing tools to ecommerce solutions to security backup systems to management tools for distributed companies to the next great idea that we haven’t even thought of yet — as much as we love creating them. These Terms of Service (“Terms”) describe our commitments to you, and your rights and responsibilities when using our services. Please read them carefully and reach out to us if you have any questions. If you don’t agree to these Terms, don’t use our services.

If you are a user in countries located in the European Economic Area, Switzerland, or the United Kingdom (“European User”), some special terms apply to you as mentioned below.

We’ve made these Terms available under a Creative Commons Sharealike license, which means that you’re more than welcome to copy them, adapt them, and repurpose them for your own use. Just make sure to revise them so that your Terms of Service reflect your actual practices. Also, if you do use these Terms, we’d appreciate a credit and link to Automattic somewhere on your website. You can grab a copy of these Terms and other legal documents on GitHub.

Terms of Service

These Terms govern your access to and use of the products and services we provide through or for WordPress.com, WooCommerce.com, WooCommerce Shipping & Tax, WooPay, Jetpack.com, VaultPress.com, Happy.Tools, Jetpack CRM, MailPoet, WPScan, and WordPress.com Courses (collectively, “Services”). Please note that WooCommerce-related products and services are intended for commercial use and you acknowledge that your use is that of a representative of a business (as defined by applicable law) and not that of a consumer.

These Terms also govern visitors’ access to and use of any websites that use our Services, like the websites that our users create on WordPress.com. Please note though that the operators of those websites may also have their own separate terms of use. For some of Automattic’s other products, services, and programs, such as Akismet, Crowdsignal, Newspack, WordPress VIP, our Affiliate Program, and our Refer-A-Friend Program, additional or separate terms may apply. Please read these Terms carefully before accessing or using our Services. By accessing or using any part of our Services, you agree to be bound by all of the Terms and all other operating rules, policies, and procedures that we may publish via the Services from time to time (collectively, the “Agreement”). You also agree that we may automatically change, update, or add on to our Services as stated in the Terms, and the Agreement will apply to any changes.

1. Who’s Who

“You” means any individual or entity using our Services. If you use our Services on behalf of another person or entity, you represent and warrant that you’re authorized to accept the Agreement on that person’s or entity’s behalf, that by using our Services you're accepting the Agreement on behalf of that person or entity, and that if you, or that person or entity, violates the Agreement, you and that person or entity agree to be responsible to us. Please see below to determine which entity your Agreement is with, which depends on where you reside and which Services you use. We use the term “Designated Countries” to refer to Australia, Canada, Japan, Mexico, New Zealand, Russia, and all countries located in Europe. All Automattic Services (except WooCommerce)

  • If you reside outside of the Designated Countries: Automattic Inc.
  • If you reside in the Designated Countries: Aut O’Mattic A8C Ireland Ltd.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment