question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

export adds a / to path of static resources

See original GitHub issue

The export feature works nearly perfectly, but all my static resources got an extra / in front of them, making them break. building from the blog or portfolio template, if I export

src="{% static 'images/heroImage.jpg' %}"

It generates out too

src="/static/images/logo.jpg"

When it should be

src="static/images/logo.jpg"

maybe a feature request for a modal asking the domain you will be hosting the site on would make sense (and prefix it to the path)? That way all resource links are absolute, a best practice.

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
cjridercommented, Oct 12, 2015

hey all. I fixed this for myself with an ugly hack.

This is a plugin, which overrides the default static and url tags and computes relative URLS using the builtin python relpath() Happy if someone else wanted to clean this up and add a config flag. For now it’s clean enough for my purposes.

#coding:utf-8
from six.moves import urllib
from django import template
from os.path import relpath
from os.path import dirname


def static(context, link_url):
    """
    Get the path for a static file in the Cactus build.
    We'll need this because paths can be rewritten with fingerprinting.
    """
    #TODO: Support URLS that don't start with `/static/`
    site = context['__CACTUS_SITE__']
    page = context['__CACTUS_CURRENT_PAGE__']

    url = site.get_url_for_static(link_url)

    if url is None:

        # For the static method we check if we need to add a prefix
        helper_keys = [
            "/static/" + link_url,
            "/static"  + link_url,
            "static/"  + link_url
        ]

        for helper_key in helper_keys:

            url_helper_key = site.get_url_for_static(helper_key)

            if url_helper_key is not None:
                return relpath(urllib.parse.urljoin( site.static_path, helper_key), dirname(page.absolute_final_url))

        url = link_url

    return relpath(urllib.parse.urljoin( site.static_path, link_url), dirname(page.absolute_final_url))



def url(context, link_url):
    """
    Get the path for a page in the Cactus build.
    We'll need this because paths can be rewritten with prettifying.
    """
    site = context['__CACTUS_SITE__']
    page = context['__CACTUS_CURRENT_PAGE__']

    url = site.get_url_for_page(link_url)

    if url is None:

        # See if we're trying to link to an /subdir/index.html with /subdir
        link_url_index = os.path.join(link_url, "index.html")
        url_link_url_index = site.get_url_for_page(link_url_index)

        if url_link_url_index is None:
            logger.warn('%s: page resource does not exist: %s', page.link_url, link_url)

        url = link_url

    if site.prettify_urls:
        return relpath(urllib.parse.urljoin(site.url,  url.rsplit('index.html', 1)[0]), dirname(page.absolute_final_url))


    return relpath(urllib.parse.urljoin(site.url, url), dirname(page.absolute_final_url))


def preBuild(site):
    register = template.Library()
    register.simple_tag(takes_context=True)(url)
    register.simple_tag(takes_context=True)(static)
    template.base.builtins.append(register)
0reactions
psqlcommented, May 3, 2016

@cjrider is there anything special I need to do, to get this plugin to work? Do I just toss it into a .py file and dump it into the plugin directory? Do I need to include it?

Sorry, I’m a total noob with the plugin paradigm in cactus.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generated static files html files have wrong assets paths #8158
I'm tried to generate a static site with Next js v9.0.2 and got assets linking by default to /_next/static/something/something.js . But by ...
Read more >
LWC loadScript from static resource with export inside
I have tried modified the library (the calc.js file) like removing export keyword and it load successfully. I have many libraries in my...
Read more >
Node: how to export/require correctly? Cannot serve static files
When I add app.use() to serve my static files to my server/index.js file it all works, but when I leave app.use insight my ......
Read more >
Referencing a Static Resource in Visualforce Markup
To reference a standalone file, use $Resource. · To reference a file in an archive, use the URLFOR function. · You can use...
Read more >
Exporting Workspace Static Files - APEX - Oracle Help Center
Export a workspace static files using the apex export command and -expFiles option.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found