notes.angad.dev
Update [2021-05-07]: This has been replaced by a static site generated by a script.
A small web app to display my notes from Google Drive. Also see notes.
2021-03-10 00:05 IST
laravel new notes.angad.dev
Install Problems
Problem 1
- phpunit/phpunit[9.3.3, ..., 9.5.x-dev] require ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.
- Root composer.json requires phpunit/phpunit ^9.3.3 -> satisfiable by phpunit/phpunit[9.3.3, ..., 9.5.x-dev].
https://stackoverflow.com/questions/43408604/php7-install-ext-dom-issue
2021-03-14 20:51 IST
Figuring out what I want this app to do
- Fetch filename from URL
- See if file exists
- Parse frontmatter, check if file is published
- Replace
[[]]links with HTML links - Replace timestamps with parsed timestamps
- Parse markdown
- Fetch last modified time for file
- Render view
I've manually pre-pended frontmatter to files I want to publish, I could've written a script but that would've taken even longer.
I'm using this package to parse frontmatter.
2021-03-14 21:29 IST
Ran into a little error withpreg_replace.
preg_replace(): Delimiter must not be alphanumeric or backslash
I just had to add backslashes around my regex to fix it.
Something else to watch out for, preg_replace doesn't alter the string you pass to it but returns a new string.
The multiline modifier came in clutch for when I had to replace the timestamps.
2021-03-14 23:01 IST
I'm using Parsedown to parse markdown. Only took me two lines!$Parsedown = new Parsedown();
$parsed_content = $Parsedown->text($markdown_content);
I also used Carbon to format the dates. Here's the code -
$file_date = \Carbon\Carbon::createFromFormat("Y-m-d", $regex_matches[1]);
$last_modified = \Carbon\Carbon::createFromTimestamp(filemtime($full_filename));
return view('document', [
'date_created' => $file_date->format('d M Y'),
'date_modified' => $last_modified->format('d M Y'),
]);
2021-03-20 05:11 IST
Giving this another go
My last attempt was pretty lackluster, so I'm going to try this again. I've started by creating a Note model. Indexing and putting these in the database seems like a good idea because last time when I tried reading them individually for the index page, it took far too long.
Here's what the migration looks like -
public function up()
{
Schema::create('notes', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('filename');
$table->dateTime('last_modified');
$table->boolean('published')->default(false);
$table->string('tags')->nullable(true);
$table->longText('content');
});
}
2021-03-20 19:14 IST
I created an artisan command, I'll use this to index notes. Here's a rough idea of what I want this command to do -- Fetch all note records from the database
lsnotes directory- Compare last modified of note record and note file
- If different and file exists -
- Run index function
- Save to database
- If file does not exist - delete record
- foreach $note in $ls_notes -
- See if record exists,
- If not - index
2021-03-20 21:28 IST
Done with the artisan command.2021-03-20 21:46 IST
Looks good! Sorted out some errors.2021-03-23 21:58 IST
Setting up Laravel Sail
composer require laravel/sail --dev
php artisan sail:install
bash vendor/bin/sail up
I got an address in use error for port 3306 and 80, so I had to shut down my local MySQL and Apache instances.
sudo service mysql stop
sudo service apache2 stop
Start containers
bash vendor/bin/sail up
Remove all containers and data
bash vendor/bin/sail down --rmi all -v