{"action":"created","issue":{"url":"https://api.github.com/repos/grow/pygrow/issues/70","labels_url":"https://api.github.com/repos/grow/pygrow/issues/70/labels{/name}","comments_url":"https://api.github.com/repos/grow/pygrow/issues/70/comments","events_url":"https://api.github.com/repos/grow/pygrow/issues/70/events","html_url":"https://github.com/grow/pygrow/issues/70","id":72810267,"number":70,"title":"Relative links in build and deploy files","user":{"login":"Willis77","id":5656866,"avatar_url":"https://avatars.githubusercontent.com/u/5656866?v=3","gravatar_id":"","url":"https://api.github.com/users/Willis77","html_url":"https://github.com/Willis77","followers_url":"https://api.github.com/users/Willis77/followers","following_url":"https://api.github.com/users/Willis77/following{/other_user}","gists_url":"https://api.github.com/users/Willis77/gists{/gist_id}","starred_url":"https://api.github.com/users/Willis77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Willis77/subscriptions","organizations_url":"https://api.github.com/users/Willis77/orgs","repos_url":"https://api.github.com/users/Willis77/repos","events_url":"https://api.github.com/users/Willis77/events{/privacy}","received_events_url":"https://api.github.com/users/Willis77/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-03T14:07:21Z","updated_at":"2015-08-03T02:50:21Z","closed_at":null,"body":"This may not be an error - I could just be missing something. When I **run** growsdk or codelab, all the links within the pages and sub-pages are fine. It appears that somehow within the server, all static items are always available at \"/static/\" regardless of path. When I generate the sites,however, with either build or deploy, the directory structure is not reflected in the links.\r\n\r\nIn codelab, for example, the static directory is referenced throughout in this way: \r\n\r\n```\r\nhref=\"/static/css/main.min.css\"\r\n```\r\n\r\nBut for the generated static site, what's really needed is the following.\r\n\r\nAt the root:\r\n\r\n```\r\nhref=\"static/css/main.min.css\"\r\n```\r\n\r\nFrom the pages:\r\n\r\n```\r\nhref=\"../static/css/main.min.css\"\r\n```\r\n\r\nAnd from the posts:\r\n\r\n```\r\nhref=\"../../static/css/main.min.css\"\r\n```\r\n\r\nIs this something that's supposed to be addressed through configuration? Or from manipulating the url from within the view?\r\n\r\nA related problem seems to crop up if you set the root path. If you do so, you have to (logically) change where the static directory is served from in order to cause the build to place the static directory within the new root path directory. (404 page winds up outside, too, FWIW.) But changing where the static directory is served from does not change the generated links to:\r\n\r\n```\r\nhref=\"/newrootpath/static/css/main.min.css\"\r\n```\r\n\r\nThey remain:\r\n\r\n```\r\nhref=\"/static/css/main.min.css\"\r\n```\r\n\r\nAgain, this could be my ignorance. I'm still trying to figure it all out. But it is surprising in that the build & deploy results do not match those of the results of the built-in server.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/grow/pygrow/issues/comments/127106217","html_url":"https://github.com/grow/pygrow/issues/70#issuecomment-127106217","issue_url":"https://api.github.com/repos/grow/pygrow/issues/70","id":127106217,"user":{"login":"jeremydw","id":646525,"avatar_url":"https://avatars.githubusercontent.com/u/646525?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremydw","html_url":"https://github.com/jeremydw","followers_url":"https://api.github.com/users/jeremydw/followers","following_url":"https://api.github.com/users/jeremydw/following{/other_user}","gists_url":"https://api.github.com/users/jeremydw/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremydw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremydw/subscriptions","organizations_url":"https://api.github.com/users/jeremydw/orgs","repos_url":"https://api.github.com/users/jeremydw/repos","events_url":"https://api.github.com/users/jeremydw/events{/privacy}","received_events_url":"https://api.github.com/users/jeremydw/received_events","type":"User","site_admin":false},"created_at":"2015-08-03T02:50:21Z","updated_at":"2015-08-03T02:50:21Z","body":"Hey there – I just wanted to give you a little update on the subject of this issue (paths to static files defined by `static_dirs`). In *0.0.51* we implemented `g.static` (before it was unimplemented). See the release notes here: https://github.com/grow/pygrow/releases/tag/0.0.51 and the documentation here: http://growsdk.org/docs/templates/#gstatic\r\n\r\nHere's example usage:\r\n\r\n```\r\n# In podspec.yaml\r\nstatic_dirs:\r\n- static_dir: /source/images/\r\n  serve_at: /static/images/\r\n```\r\n\r\n```\r\n# In /views/base.html\r\n<img src=\"{{g.static('/source/images/file.png')}}\">\r\n\r\n# Results in\r\n<img src=\"/static/images/file.png\">\r\n```\r\n\r\nBasically, `g.static` returns a StaticFile object when given the pod path (the internal path) of a static file in a `static_dirs` directory. From that StaticFile object, you can access the `url.path` property to resolve the file's serving path. This is particularly useful as it allows you to change a file's URL path without moving the file internally – and it also helps avoid broken links as the tag raises an error if it cannot find the file locally.\r\n\r\nOne note – `url.path` always returns the absolute path of the file's serving path.\r\n\r\nWhile the `url.path` property is the only property implemented right now, in the future we can expand the available properties to add more features – such as a theoretical `url.relative_path` that would presumably return the relative path of the StaticFile based on the current document that's wondering.\r\n\r\nAnyway, does the current implementation of `g.static` meet your needs? If not, what else would you find useful? Thanks!"}}