marcominerva/TinyCMS

Add custom stylesheets

Closed this issue · 4 comments

It is necessary to add the ability to provide custom stylesheets (links and direct content), both at site level as well as page level.

Hi Marco, I was thinking about this issue and how to implement it.

I expect that some stylesheets can be repurposed in the various pages/site, so I thought of 3 more tables:

  1. StyleSheets: this is the table where we will store every stylesheets
  2. ContentPagesStyleSheets: this is the link table for a ContentPage and one or more StyleSheet
  3. SitesStyleSheets: this is the link table for a Site and one or more StyleSheet

Into the details, the first one will be something like this:

Id Name ScriptUrl RawContent
guid Sort of human identification the url script css raw content

There will be a constraint to check that at least one column between ScriptUrl and RawContent is not null.

The other two are just for the join:

Id ContentPageId StyleSheetId
guid Id of the ContentPage Id of the StyleSheet
Id SiteId StyleSheetId
guid Id of the Site Id of the StyleSheet

What do you think about this implementation?

Generally speaking, your design is correct, but keep in mind that the keyword of the project is Tiny. Adding three tables to handle stylesheets makes the engine much less simple, in particular if you consider that typically we have a CSS at site level or page level, while having a stylesheet shared by a bunch of pages is quite rare.

For this reason, to keep things as simple as possible, I was thinking about the following solution:

  1. Adding two columns, StyleSheetUrls and StyleSheetContent, to the Sites tables;
  2. Adding two columns, StyleSheetUrls and StyleSheetContent, to the ContentPages tables.

In the StyleSheetUrls, we place the URIs of all the stylesheets, for example separated by a semicolon, while in StyleSheetContent we insert the raw content. Using a single column for all the URIs can be a bad practice, but, as always, remember the simplified scenario of TinyCMS. In this way, if we have a style that we want to be used by all the pages of a particular site, we just need to insert it in the Sites table, while we use the new columns in the ContentPages if we want to apply a style to a particular page only.

Then, when we get a page from the database, we read also the new columns (I imagine to use a Dapper Type Handler for the StyleSheetsUrls column) and add the corresponding HTML to the page.

According to the scenario of TinyCMS, does this design sound good?

Sounds good to me, I'll make a PR as soon as I get back from vacation

Closed by #22