Code Monkey home page Code Monkey logo

jblog's Introduction

Welcome to jBlog!

jBlog is the basic content management system (CMS) powering my portfolio that I've been constantly developing since early 2004. I've decided to open-source it now that I have ported it to Angular in the hopes that someone else can learn from it.

History

jBlog started off as a pure PHP site that I intended to integrate with the PHP-powered web forum software I was using at the time. However, I never fully got around to getting the integration working and after a few years I closed down the forum software as it had been replaced with a variety of social networks that did a better job.

I've ported the front-end to Angular in an effort to learn the framework as well as share knowledge (hence the public GitHub repo!). However, the backend remains written in PHP, as that is all my web hosting provider allows me to use on my hosting package - it's a LAMP package that I bought a long time ago and now rely on for more than just site hosting so I don't plan on switching provider!

Getting started

The site is an Nx-powered monorepo comprising of an Angular front-end and a PHP back-end. Therefore, in order to build and run the site, you'll need to have a development environment with the latest LTS versions of Node.js and PHP (currently Node.JS 18 and PHP 8.2).

The PHP-side of the monorepo is currently unhooked from Nx as I try and work out how to make them play nice together. As such, the PHP instructions are run outside of the Nx environment.

TL;DR:

  1. Install node and npm (or yarn) and composer
  2. Pull down the code (git clone ...)

Front-end:

  1. Install JavaScript packages (dependencies) using npm (or yarn): npm install
  2. Run a development server using npm run serve

Back-end

  1. Install PHP packages: php ./composer.phar install
  2. Have a PHP server serve the backend (/libs/api/src) at localhost:8080/api

Setting up the development environment

Requirements for front-end work:

  • Node.js (latest LTS)
  • A web browser you're familiar with for debugging in

Requirements for back-end work:

  • PHP (latest LTS)
  • Composer
  • A way to get PHP to serve the contents of the /libs/api/src directory.
  • Some way to edit SQLite databases.

If you're unsure what editor to use for coding, I recommend Visual Studio Code. It will load the recommended configuration and suggest some plugins to make development easier when the root directory is selected.

Developing and running the Front-end

The front-end is written using the Angular framework in TypeScript, and must be transpiled in order to run in a web browser. To do this, you'll need to pull down the Angular dependencies using npm (or yarn). Navigate to the root directory of this repository in a terminal and run npm install (or yarn install) to do this.

Once this is complete, a live-reload development server can be run with npm run serve. This server can be accessed by visiting http://localhost:4200 in a web browser. Every time there is a code change, the web browser will automatically reload with the latest changes. The server will serve a development build of the site.

Running npm run build will generate a dist folder that can be upload onto a web server containing. This is a production build and therefore with minification and tree shaking applied.

Different configurations of the site builds request the backend from different locations. These are provided by the files in apps/jblog/src/environments/ which will be swapped in to the build using the values defined in apps/jblog/project.json.

Unit testing

Running npm run test will run unit tests using the Jest testing framework. Jest emulates a browser using JSDom so these tests should be able to run on environments without a browser installed (i.e. CI pipelines).

End-to-end testing

Running npm run e2e will run the tests using Cypress in a CI format. Running npm run e2e:watch will run the Cypress tests interactively and watch for any code changes.

Developing and running the back-end

To get the back-end to work, the configuration file and SQLite databases need to be generated.

Enabling authentication

While having a user account set up for the site is optional (you can add posts by modifying the database directly), the authentication libraries need to be fetched using composer before the back-end can be run.

php ./composer.phar install

The rest of this section is optional if user setup is unwanted.

Generate a private and public key pair for JWT signing by running the following:

ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub

Move the jwtRS256.key and jwtRS256.key.pub to a secure location on the server and update the paths in the settings file.

Configuration file

The PHP scripts are configured by the file /libs/api/src/conf/settings.php. A template file, settings-template.php, can be used as a starting point for this. The variables are documented within that file.

Creating the SQLite database

The SQLite database is generated with the SQL file in the /libs/api/src/conf/setup.sql file. Note that if you have specified a different database prefix in the settings file, you will need to adjust the table names in the SQL as appropriate.

There are a few 'gotchas' when adding data to the tables manually. Many of the data storage decisions date back to the initial versions of the software and I haven't changed the way this part of the system works since the initial versions.

Some general things to note:

  • *_date fields are Unix timestamps, which means they're stored as the number of seconds since 1st Jan 1970, 00:00 UTC.
  • *_id fields must be unique and are the way the system refers to a record.

Unit testing

This needs to be set up…

Design philosophy for contributing

Last updated January 2019

Core

  • All colours are defined as CSS variables in apps/jblog/src/theme/colors/palette-*.css. Refer to this file to use colours.
  • All dimensions are defined need to be refactored out into CSS variables and placed in the apps/jblog/src/styles.scss :root rule.

Basics

  • The colour palette marked primary-a should be used for large background areas.
  • The colour palette marked primary-b should be used for small points of interest or calls to action.
  • Small cards should mainly be imagery. Avoid small all-text cards.
  • Larger cards which contain mostly text (articles, for example) should not let the text go full-width.
  • Interactive items with shadows should raise 0.5px and use the relevant hover shadow.

Measurements, margins, etc

  • Always use px units for elements and components, unless something needs to be separated by a space character’s width. In that case, use em units (0.5em is approximately a space character’s width).
  • When a margin or padding needs to be defined, it should be in a multiple of 4px.
  • Only use the .grid CSS class to add a 12 column CSS grid to any full-width element placed inside a .container.

Transitions and animations

  • Default transition timing is .2s (and this needs to be refactored into a CSS variable);
  • Default transition easing needs to be finalised.
  • The only time an element can move outside the bounds of the viewport is when the user changes route.

Slow-loading content

  • Use the pulse loading effect on ghost elements that appear the same size as the content that will load in (TO DO).
  • If the size of the content is unknown and the transition of the pulse loading effect to the content will be jarring, place a centre-aligned loading spinner in the area the content will appear.

jblog's People

Contributors

jbrowneuk avatar dependabot[bot] avatar

Watchers

 avatar

Forkers

blmsl

jblog's Issues

Exception due to animation not playing when navigating from home page

Expected Behavior

  1. Navigate to homepage
  2. Navigate to another page, i.e. journal
  3. Page transition happens and no error thrown

Actual Behavior

An exception is logged to the console when navigating away from the home page. No route transition happens

Steps to Reproduce the Problem

  1. Navigate to homepage
  2. Open developer console
  3. Navigate to another page, i.e. journal

Error logged:

ERROR Error: Unable to process animations due to the following failed trigger transitions
 @carouselTransitions has failed due to:

- `query(":enter")` returned zero elements. (Use `query(":enter", { optional: true })` if you wish to allow this.)

Specifications

  • Version: git commit 6af4d84
  • Platform: all browsers

Unit tests don't work

Expected Behavior

Running npm run test or ng test on the codebase should run unit tests.

Actual Behavior

Running ng test fails with 20 tests not running at all:

Chrome 57.0.2987 (Mac OS X 10.12.4): Executed 24 of 24 (20 FAILED) (1.108 secs / 0.579 secs)

Steps to Reproduce the Problem

  1. cd to project root directory.
  2. run npm run test

Specifications

  • Version: 3.1.0-beta1
  • Platform: Mac OS 10.12.4, node 7.5.0, npm 4.1.2

Journal no longer updates tab title

Expected Behavior

Navigating to any page on the journal should update the tab title with the following rule set:

  • Post list: site title: Journal
  • Single post: site title: <post title>

Actual Behavior

Tab title is not updated. If navigating from a different section, the previous section title is shown.

Steps to Reproduce the Problem

  1. Navigate to any section of the site, i.e. /code. Note the tab title is set to site title: Code
  2. Click the navigation item to access the Journal. Note the title does not update

Specifications

  • Version: git commit 6af4d84
  • Platform: all browsers

IE11 displays blank page

Expected Behavior

Page loads and renders in IE 11.

Actual Behavior

Page fails to render with SCRIPT5007: Unable to get property 'apply' of undefined or null reference
Polyfills need to be uncommented in the polyfill file.

Steps to Reproduce the Problem

  1. Open IE
  2. Load site (http://jbrowne.me.uk)

Specifications

  • Version: 3.1.0-beta1
  • Platform: Windows 10 x64

Readme is insufficient for setting up dev environment

Expected Behavior

By reading the readme, you should at least be able to set up a development environment, or there should be other supporting documentation to be able to do this.

Actual Behavior

There are no concrete instructions for setting up a development environment on a new machine.

Steps to Reproduce the Problem

Specifications

  • Version: 3.1.0-beta1
  • Platform: all

Admin panel: editing a post does not show word or character count

Expected Behavior

When editing a post in the admin panel, the number of words and characters remaining should be displayed.

Actual Behavior

The text characters words is shown

Steps to Reproduce the Problem

  1. Open ACP
  2. Edit a post
  3. Note the hint text under the text area

Single post view fails to load post

Expected Behavior

Single post view displays content.

Actual Behavior

Single post view fails with an exception:

ERROR TypeError: Cannot read property 'length' of undefined
    at n.hasTags (/1.ff759fa7d5deaa6076d1.chunk.js:1)

Steps to Reproduce the Problem

  1. Navigate to a post (i.e. 292) - url/journal/292

Specifications

  • Version: 3.1.0-beta1
  • Platform: Any

Unit tests rarely work

Expected Behavior

Running unit tests should work

Actual Behavior

Running unit tests causes epic explosions and death (of the site or unit tests).

Unit tests in this project rarely work. In order to get the site to an acceptable state, tests should consistently work before new code is developed.

Parallax positioning fails if image is not loaded in time

Expected Behavior

When the page loads on a slow connection, the parallax backdrop is hidden and its position is not calculated until the image is loaded.

Actual Behavior

The parallax backdrop position is calculated on the bounds of the alternate text, causing the image to jump on first scroll.

Steps to Reproduce the Problem

  1. Load a page with parallax header backdrop on a slow connection
  2. Scroll down

Specifications

  • Version: 3.1 WIP
  • Platform: All

Selecting an album and then switching page has a jarring jump

Expected Behavior

When switching page (i.e. Pressing next) after switching to a different album, the page does not scroll to the top.

Actual Behavior

Page scrolls to the top as the route has changed.

Steps to Reproduce the Problem

Specifications

  • Version:
  • Platform:

Switching journal pages displays “No posts”

Expected Behavior

Journal - change page, get loading text.

Actual Behavior

Journal - change page, get “No posts” briefly before posts load.

Steps to Reproduce the Problem

See actual behaviour.

Specifications

  • Version: 3.2 fix-post-content branch.
  • Platform: mainly Safari.

This looks like it may have something to do with the position of the call to this.onStartLoading(); in the post list component. Might need to be in the for each loop as that appears to be called each time the component is reused.

Journal pagination does not refresh when a tag is applied

Expected Behavior

The pagination at the bottom of the post list page reflects the number of pages for the currently selected tag if a tag has been added to the view filter.

Actual Behavior

The pagination shows the total number of pages for all posts no matter what.

Steps to Reproduce the Problem

  1. Load the journal post list for a journal with more than one page of posts. Note the number of pages in the pagination.
  2. Select a tag on a post which has less pages. Note the number of pages on the pagination does not change.
  3. Click on the last visible page number. "No posts" is displayed and the pagination will now update.

404 page is visually inconsistent

Expected Behavior

The 404 page should use current palette and container theme. SVG could use currentcolor or similar to achieve.

Actual Behavior

404 page is purple and the container has no padding.

Steps to Reproduce the Problem

  1. Navigate to https://jbrowne.io/404

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.