Base URL option in generate form doesn't work when running Drupal in a sub-directory

Created on 9 January 2022, almost 3 years ago
Updated 17 July 2023, over 1 year ago

Problem/Motivation

I am running my Tome Drupal site in a subfolder, so it's URL is http://localhost:8888/tome-blog/web and the HTML static files get put in http://localhost:8888/tome-blog/html.

I went to admin/config/tome/static/generate and entered 'http://localhost:8888/tome-blog/html/' as the base URL and generated the static site.

However, my site at http://localhost:8888/tome-blog/html/ doesn't show any CSS because all the URIs in the HTML look like this:

    <link rel="stylesheet" media="all" href="/sites/default/files/css/css_pu8n-9XqDcbjLssKWX6HTUj95K8nWYuNQZ1q3rfKyik.css" />

with the initial /.

I was expecting the base URL value to be prepended to all URIs in the generated HTML, or better still, defined with https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Tome Static

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom joachim

    I've got a quick hack working with an outbound path processor service:

    class SiteRootOutboundPathProcessor implements OutboundPathProcessorInterface {
    
      /**
       * {@inheritdoc}
       */
      public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
        if (!$request) {
          // WTF? Why is $request sometimes NULL?
          return $path;
        }
    
        if (!$request->attributes->has(StaticGeneratorInterface::REQUEST_KEY)) {
          return $path;
        }
    
    
        // Hardcoded for now - should get this value from the base URL option in the form.
        $options['base_url'] = 'http://localhost:8888/tome-blog/html/tome-blog/web';
    
        return $path;
      }
    
    }
    
Production build 0.71.5 2024