Code Monkey home page Code Monkey logo

hosting-media-theme's Introduction

Lombiq Hosting - Media Theme for Orchard Core

Lombiq.Hosting.MediaTheme NuGet Lombiq.Hosting.MediaTheme.Bridge NuGet Lombiq.Hosting.MediaTheme.Deployer NuGet Lombiq.Hosting.MediaTheme.Tests.UI NuGetLombiq.Hosting.MediaTheme.Targets NuGet

About

The Media Theme feature will allow developers to host their themes in the Orchard Core Media Library, including templates and assets. This is useful in SaaS scenarios where you can't allow everyone to develop full Orchard themes, but still want to make the usual Orchard theming experience available to all users. Media Theme allows full theming of sites running on DotNest, the Orchard SaaS, too. Watch a demo video of it from the Orchard Community Meeting here.

We at Lombiq also used this SDK for the new Show Orchard website when migrating it from Orchard 1 DotNest to DotNest Core (see case study and the theme's source code).

Do you want to quickly try out this project and see it in action? Check it out in our Open-Source Orchard Core Extensions full Orchard Core solution and also see our other useful Orchard Core-related open-source projects!

Documentation

Getting started

There are two Orchard Core extensions and a targets extension in this project:

  • Lombiq.Hosting.MediaTheme.Bridge: An Orchard Core module that enables the core logic required for hosting your theme the Media Library.
  • Lombiq.Hosting.MediaTheme: An Orchard Core theme that bootstraps the Media Theme logic using the Lombiq.Hosting.MediaTheme.Bridge module. With this theme active you can dynamically change the base theme from the Admin UI or using recipes.
  • Lombiq.Hosting.MediaTheme.Targets: Provides automatic Media Theme package creation in the project. Checkout its readme file.

To get started, you'll need to add Lombiq.Hosting.MediaTheme and Lombiq.Hosting.MediaTheme.Bridge NuGet packages to your web project. Set the Lombiq.Hosting.MediaTheme as the active site theme from the Admin UI or recipe.

Once the theme is enabled, it'll look for templates and assets in the Media Library. Go to Media Library and create the _MediaTheme folder, where you can put shape templates inside the Templates folder (see limitations below), and assets inside the Assets folder.

Note that the .liquid extension is not allowed in Media Library by default, which might be an issue with a few of your assets as well. Please update the Media settings as described here.

Using a base theme

Media Theme supports base themes. First, enable the theme you want to use as a base theme. Then go to the Admin UI → Configuration → Media Theme page and select the one you want to use. You won't be able to update the base theme dynamically if the Media Theme is not active even if you are using the Media Theme logic provided by the Lombiq.Hosting.MediaTheme.Bridge.

Limitations

  • Shape templates must be .liquid files. You can't use Razor templates.
  • Shape template file names must be valid template, not template file names, i.e., may not contain . and - characters (but use the _ and __ notation instead). Note that these don't just differ in the interchangeable characters but may also differ in the order of sections. E.g. [Stereotype]_[DisplayType]__[PartType]__[PartName]__[DisplayMode]_Display is "Widget_Summary__ServicePart__Services__CustomMode_Display" as template name but "Widget-ServicePart-Services-CustomMode.Display.Summary.liquid" as a file name (note e.g. "Summary" being in a different location). See the docs for details.
  • The theme may include static resources in its wwwroot folder as any theme. You can also build those from source files like SCSS files as usual.
  • The theme mustn't include any C# code apart from its Manifest.
  • Folders within the Views folder are not supported. It also means that MVC views can't be overridden or custom shape harvesters can't be used.

Local development

If you want to build a theme that'll eventually end up in the Media Library, you can develop it as usual but make sure the Lombiq.Hosting.MediaTheme.Bridge module is its dependency. You can set a base theme for your theme from the Manifest as usual too. Note that you won't be able to change the base theme dynamically from the Admin UI during local development.

You can proceed with developing your theme as you'd typically do: put the templates inside the Views folder and static resources inside the wwwroot folder; however, keep the limitations mentioned above in mind.

If you want to reference assets in your templates, you can use the /mediatheme/ prefix in URLs, like below:

{% assign 32pxIconUrl = "~/mediatheme/images/favicon-32x32.png" | href %}
{% link type:"image/png", rel:"icon", sizes:"32x32", href:32pxIconUrl, append_version:"true" %}

{% assign stylesPath = "~/mediatheme/styles/site.css" | href %}
{% style src:stylesPath %}

These use Orchard's resource manager and thus will also include a browser/proxy cache busting v parameter that updates when you deploy a new version of your theme. This will ensure that everybody sees the current version of your site's styling. Note that while the Liquid style and script tags do this by default, for link you have to add append_version like above too.

Media Theme will translate this special ~/mediatheme path to either your local theme asset path or Media Library if the file exists. This way, you don't need to update your asset URLs in your templates one-by-one when deploying them. The ~ notation of virtual paths also comes in handy if you want to work with multiple tenants using URL prefixes locally, i.e. develop multiple Media Themes for multiple sites from the same solution.

If you are developing a theme for your DotNest site you can use the DotNest Core SDK that has everything prepared for you right away.

Deployment (import/export)

Importing a deployment package created by the Deployer tool

Instead of manually uploading files to the Media Library, install the Lombiq.Hosting.MediaTheme.Deployer dotnet tool:

dotnet tool install --global Lombiq.Hosting.MediaTheme.Deployer

Then you can use it to build a deployment package of your theme:

media-theme-deploy --path [path of your theme] --base-id [base theme id] --clear [clear media hosting folder] --deployment-path [deployment path]

A specific example when run in the folder of your theme project:

media-theme-deploy --path . --base-id TheTheme --clear true --deployment-path .\Deployment
  • --base-id is optional. If not provided, the tool will try to get it from the Manifest file, and if it's not defined there either, no base theme will be used.
  • --deployment-path is optional. Without it, the package will be exported to your directory root, for example C:\MediaThemeDeployment_04Aug2022230500.zip. The parameters also have shorthand versions: -p, -i, -c, -d, respectively.

You can then take the resulting ZIP file and import it on your site from the Admin UI → Configuration → Import/Export → Package Import. Everything necessary will be configured by the package. If you don't see this menu item then first enable the "Deployment" feature under Configuration → Features.

Remote deployment with the Deployer tool

You can use Remote Deployment to accept packages created with the above-explained Deployer too via the internet, without manually uploading the ZIP file. You can use this to deploy your theme remotely from your local development environment or CI workflow too, for which we provide a ready-to-use GitHub Actions workflow.

Do the following to set up automated GitHub Actions deployments:

  1. Create a Remote Client on the Orchard admin UI → Configuration → Import/Export → Remote Clients. Use a suitable name and a strong, unique API key. If you don't see this menu item then first enable the "Remote Deployment" feature under Configuration → Features.
  2. Configure the Client API Key as a repository secret. While not strictly necessary, we recommend also storing the Client Name and Remote Deployment URL as secrets too.
  3. Add a workflow to the .github/workflows folder of your repository that executes the deploy-media-theme reusable workflow with some suitable configuration:
name: Deploy Media Theme to DotNest

on:
  push:
    branches:
      - my-dev
    paths:
      - 'src/Themes/My.Theme/**'

jobs:
  deploy-media-theme:
    name: Deploy Media Theme to DotNest
    uses: Lombiq/Hosting-Media-Theme/.github/workflows/deploy-media-theme.yml@dev
    secrets:
      URL: ${{ secrets.MY_THEME_DEPLOYMENT_URL }}
      CLIENT_NAME: ${{ secrets.MY_THEME_DEPLOYMENT_CLIENT_NAME }}
      CLIENT_API_KEY: ${{ secrets.MY_THEME_DEPLOYMENT_CLIENT_API_KEY }}
    with:
      theme-path: "src/Themes/My.Theme"
      # You can leave out base-theme-id to get it from the Manifest, or to not use a base theme at all.
      #base-theme-id: "TheBlogTheme"

If you want to use a different CI system or would like to run remote deployment from the command line otherwise, use the --remote-deployment-url, --remote-deployment-client-name, and --remote-deployment-client-api-key parameters. See this PowerShell script for an example:

$switches = @(
    '--path', '.'
    '--remote-deployment-url', 'https://localhost:44335/OrchardCore.Deployment.Remote/ImportRemoteInstance/Import'
    '--remote-deployment-client-name', 'demo'
    '--remote-deployment-client-api-key', 'Password1!'
)

media-theme-deploy @switches

Contributing and support

Bug reports, feature requests, comments, questions, code contributions and love letters are warmly welcome. You can send them to us via GitHub issues and pull requests. Please adhere to our open-source guidelines while doing so.

This project is developed by Lombiq Technologies. Commercial-grade support is available through Lombiq.

Publishing and using a version of the Deployer during local development

If you want to publish Lombiq.Hosting.MediaTheme.Deployer to test it during local development, then do the following:

  1. Pack it into a NuGet package by running dotnet pack in the project's folder.
  2. Uninstall the tool if you have it installed already: dotnet tool uninstall --global Lombiq.Hosting.MediaTheme.Deployer.
  3. Install the local version (note that without a version specified, it'll be published as v1.0.0): dotnet tool install --global Lombiq.Hosting.MediaTheme.Deployer --add-source .\nupkg --version 1.0.0.
  4. Now media-theme-deploy will use the development version.

hosting-media-theme's People

Contributors

0liver avatar barthamark avatar benedekfarkas avatar davidpuplava avatar demeszabolcs avatar dministro avatar domonkosgabor avatar luko6 avatar mzole avatar piedone avatar porgabi avatar psichorex avatar sarahelsaig avatar wasnk avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

davidpuplava

hosting-media-theme's Issues

Media Theme URLs using append_version point to wrong resource during local development (OSOE-775)

During local development of a Media Theme (I'm trying specifically with this one) you can include static resources like this:

{% assign appleIconUrl = "~/mediatheme/images/apple-touch-icon.png" | href %}
{% link rel:"apple-touch-icon", sizes:"180x180", href:appleIconUrl, append_version:"true" %}

This correctly generates this:

<link href="/mediatheme/images/apple-touch-icon.png" rel="apple-touch-icon" sizes="180x180" />

However, if you add append_version:

{% link rel:"apple-touch-icon", sizes:"180x180", href:appleIconUrl, append_version:"true" %}

Then it'll point to a wrong URL:

<link href="/media/_MediaTheme/Assets/images/apple-touch-icon.png?mediatheme=1830490569" rel="apple-touch-icon" sizes="180x180" />
  • This is most possibly due to some bug in FileVersionProviderDecorator.
  • This happened sometime between OC v1.5 and 1.7, before that it worked well.
  • This only affects local development, not the prod site.
  • Add a second asset inclusion that uses append_version to our sample template so next the UI test can catch this.

Jira issue

Missing NuGet setup (OSOE-456)

  • Lombiq.Hosting.MediaTheme.Deployer has no NuGet metadata configured in its csproj.
  • NuGet shields apart from Lombiq.Hosting.MediaTheme's are missing from the Readme.

Jira issue

Deployment action with GitHub Actions (OSOE-514)

Add a GitHub Actions composite action that can be used to deploy to a configured Orchard Core site via remote deployment.

  • Install Lombiq.Hosting.MediaTheme.Deployer.
  • Run media-theme-deploy for the configured theme.
  • Send the resulting zip file to an Orchard Core Remote Deployment endpoint, configured as a secret. This is most possibly best done also from Lombiq.Hosting.MediaTheme.Deployer (perhaps there can be just a single command to create and also send the deployment package).
  • Update the Readme section about deployment accordingly too.

Jira issue

View not taken from base theme (OSOE-529)

When using The Blog Theme as a base theme for my media theme I noticed that the search page looks really bad:

image

Note that the menu is there but invisible (white on white) unless highlighted like this. The problem is, that the Header zone doesn't get filled with what the Search override defines in The Blog Theme.

My first idea was that this limitation has something to do with this. But looking at the code briefly, I couldn't pinpoint anything obvious. Rather, our base them handling is perhaps an issue: BaseTheme is just a dependency for themes, there's nothing else special about defining it. So, our approach of adding it as such in ExtensionManagerDecorator should work. However, there's something clearly missing since defining a base theme directly in Media theme (i.e. BaseTheme = "TheBlogTheme") works:

image

I understand that I can't override views form my media theme, but views from a base theme should properly be applied. Other shape templates, i.e. Liquid files form the Views folder of The Blog Theme get applied.

Jira issue

Don't redirect but rewrite /mediatheme requests (OSOE-516)

When you use the "/mediatheme" prefix when referencing static assets, e.g. "/mediatheme/image.jpg", then request will first go to /mediatheme/image.jpg, then be redirected to the actual URL. This incurs the penalty of a second request for every asset.

While with a permanent redirect this penalty is at least paid a single time for each asset, it's still not too nice.

Instead, let's not have a redirect at all, but rewrite the URL or request in some way:

  • Replace the URL in the HTML output somehow.
  • Instead of a redirect, have a request rewrite, i.e. MediaThemeAssetUrlRedirectMiddleware should instead of a redirection load the resources and return it. Note that such loads should be cached, preferably by utilizing Media Cache that does this already.

Jira issue

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.