#2641·middleman

i18n + proxy dynamic pages

Author: joapuiibCreated May 24, 2023Updated Jun 27, 2024
Labelsnotstale

Expected behavior and actual behavior

I've seen that there are issues with wontfix tag already with a similar issue, but I have read them and I don't see how the solutions given apply to my problem, so I'm writing a new issue. Sorry for the inconvenience.

I'm trying to duplicate a resource using a proxy. My goal is to generate a copy of some resources (marked with generate_copy: true in the frontmatter) and modify its contens using a variable.

ruby
ready do
  sitemap.resources.select {|p| p.data[:generate_copy] }.each do |page|
    page_lang = page.options[:locale]
    if page.instance_of? Middleman::Sitemap::ProxyResource
      page = page.target_resource 
    end

    new_path = page.path.gsub(/(.*\/)(.*?)(\..*)/, '\1\2_new\3')

    proxy new_path, page.path, :locals => {
      :more_content => true
    }
  end

Given a file source/dir/test.html.erb:

markdown
---
generate_copy: true
---
# Test
This is the main content

<% if defined?(more_content) && more_content %>
- This is added content to the copy
<% end %>

The previous code works OK and it generates the resource /dir/test_new.html with the added content, which uses the default language and it's not proxied.

However, I've been trying to achieve the same behavior with localized files, but since I18n proxies its resources, an exception is raised because it's not allowed to proxy another proxy.

Given the file source/dir/test.en.html.erb with the same contents, the exception You can't proxy en/dir/test_new.html to dir/test_new.en.html which is itself a proxy. is raised.

Raised in: https://github.com/middleman/middleman/blob/5a2726fa26ba691f35fa5225b4944f954c4367fc/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb#L93

The expected behavior would be to be able to generate a copy in /en/dir/test_new.html.

Is any other way to git this to work or bypass this exception?

Thanks.