{"action":"created","issue":{"url":"https://api.github.com/repos/assetgraph/assetgraph/issues/234","labels_url":"https://api.github.com/repos/assetgraph/assetgraph/issues/234/labels{/name}","comments_url":"https://api.github.com/repos/assetgraph/assetgraph/issues/234/comments","events_url":"https://api.github.com/repos/assetgraph/assetgraph/issues/234/events","html_url":"https://github.com/assetgraph/assetgraph/issues/234","id":55398463,"number":234,"title":"moveAssets transform doesn't appear to actually rewrite URLs to relative URLs in parent assets.","user":{"login":"jscinoz","id":850958,"avatar_url":"https://avatars.githubusercontent.com/u/850958?v=3","gravatar_id":"","url":"https://api.github.com/users/jscinoz","html_url":"https://github.com/jscinoz","followers_url":"https://api.github.com/users/jscinoz/followers","following_url":"https://api.github.com/users/jscinoz/following{/other_user}","gists_url":"https://api.github.com/users/jscinoz/gists{/gist_id}","starred_url":"https://api.github.com/users/jscinoz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jscinoz/subscriptions","organizations_url":"https://api.github.com/users/jscinoz/orgs","repos_url":"https://api.github.com/users/jscinoz/repos","events_url":"https://api.github.com/users/jscinoz/events{/privacy}","received_events_url":"https://api.github.com/users/jscinoz/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-01-25T05:17:51Z","updated_at":"2015-01-26T00:32:39Z","closed_at":"2015-01-26T00:32:39Z","body":"Hi,\r\n\r\nI'm implementing a site archival tool based upon assetgraph. Assetgraph correctly retrieves the entry point page, and any linked resources (subject to the defined followRelations constraints), however I'm running into a problem when I attempt to use a moveAssets transform to rewrite any absolute URLs to relative URLs.\r\n\r\nI'm using the following URL mapping function in the call to the moveAssets transform:\r\n\r\n```javascript\r\nfunction(asset) {\r\n    let origUrl = asset.url,\r\n        newUrl = asset.url.replace(\r\n            new RegExp(\"^\" + rootUrl + \"/\"),\r\n            \"./\"\r\n        );\r\n\r\n    console.log(\"Moving \" + origUrl + \" -> \" + newUrl);\r\n\r\n    return newUrl;\r\n})\r\n```\r\n\r\nWhen the assetgraph is eventually written out, any `<link>`, `<script>`, and `<img>` elemenets still have their original absolute URLs, rather than the expected relative URLs. After reading through the source and experimenting with a number of different prefixes for the value of newUrl (in the above example), and even reosrting to the hack of directly modifying asset._url to bypass the setter method, it doesn't appear possible to have assetgraph rewrite an input to contain relative URLs. Is this a bug, or am I missing something?\r\n\r\nIf it's any help, below is the above transform in context:\r\n\r\n```javascript\r\nlet crawlUrl = Promise.coroutine(function *(url) {\r\n    // TODO: Also, script out dead scripts (i.e. those on other domains);\r\n    let ignoredTypes = [ \"HtmlAnchor\" ],\r\n        rootUrl = url,\r\n        graph = new AssetGraph({ root: rootUrl }),\r\n        query = AssetGraph.query;\r\n\r\n    let crawlDeferred = Promise.defer();\r\n\r\n    graph.on(\"addAsset\", function(asset) {\r\n        console.log(\"Loading \" + asset.urlOrDescription + \"...\");\r\n\r\n        asset.on(\"load\", function(asset) {\r\n            console.log(\"Loaded \" + asset.urlOrDescription + \".\");\r\n        });\r\n    })\r\n    .loadAssets(rootUrl)\r\n    .populate({\r\n        followRelations: {\r\n            type: query.not(ignoredTypes),\r\n            hrefType: [ \"relative\", \"rootRelative\" ]\r\n        }\r\n    })\r\n    // XXX: Rename files to hash of contents?\r\n    .moveAssets({\r\n        isInline: false,\r\n        url: query.not(rootUrl)\r\n    }, function(asset) {\r\n        let origUrl = asset.url,\r\n            newUrl = asset.url.replace(\r\n                new RegExp(\"^\" + rootUrl + \"/\"),\r\n                \"./\"\r\n            );\r\n\r\n        console.log(\"Moving \" + origUrl + \" -> \" + newUrl);\r\n\r\n        return newUrl;\r\n    })\r\n    .moveAssets({ url: rootUrl }, \"index.html\")\r\n    .writeAssetsToDisc({ isLoaded: true }, \"/tmp/ag-test-output\")\r\n    .run(function() {\r\n        crawlDeferred.resolve();\r\n    });\r\n\r\n    // Wait for graph to be in final state\r\n    yield crawlDeferred.promise;\r\n\r\n    return graph.findAssets({ isInline: false }).map(function(asset) {\r\n        let resourcePath = asset.url.replace(new RegExp(\"^\" + rootUrl), \"\"); \r\n\r\n        console.log(\"resourcePath: \" + resourcePath);\r\n\r\n        let contentBuf = asset.rawSrc;\r\n        if (asset.contentType === \"application/x-javascript\") { \r\n            // Deal with assetgraph returning obsolete content type\r\n            contentBuf.contentType = \"application/javascript\";\r\n        } else {\r\n            contentBuf.contentType = asset.contentType;\r\n        }\r\n\r\n        contentBuf.name = resourcePath;\r\n\r\n        return contentBuf;\r\n    });\r\n});\r\n```"},"comment":{"url":"https://api.github.com/repos/assetgraph/assetgraph/issues/comments/71402278","html_url":"https://github.com/assetgraph/assetgraph/issues/234#issuecomment-71402278","issue_url":"https://api.github.com/repos/assetgraph/assetgraph/issues/234","id":71402278,"user":{"login":"jscinoz","id":850958,"avatar_url":"https://avatars.githubusercontent.com/u/850958?v=3","gravatar_id":"","url":"https://api.github.com/users/jscinoz","html_url":"https://github.com/jscinoz","followers_url":"https://api.github.com/users/jscinoz/followers","following_url":"https://api.github.com/users/jscinoz/following{/other_user}","gists_url":"https://api.github.com/users/jscinoz/gists{/gist_id}","starred_url":"https://api.github.com/users/jscinoz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jscinoz/subscriptions","organizations_url":"https://api.github.com/users/jscinoz/orgs","repos_url":"https://api.github.com/users/jscinoz/repos","events_url":"https://api.github.com/users/jscinoz/events{/privacy}","received_events_url":"https://api.github.com/users/jscinoz/received_events","type":"User","site_admin":false},"created_at":"2015-01-26T00:32:39Z","updated_at":"2015-01-26T00:32:39Z","body":"Thank you for your help, it's now working! The [code](https://github.com/jscinoz/everarchive) involved certainly needs to be cleaned up, but now I can continue with the next component.\r\n\r\nI'll likely rework the current logic that writes the results into GridFS into a proper transform later, when I do, would you be interested in merging it? If so, I'll send through a PR when I get it done."}}