Middleman Blog标记页面不反映区域设置

时间:2019-06-07 01:43:18

标签: internationalization tags middleman

当前遇到的问题是,博客标记页的URL中没有包含语言环境(从而忽略了当前选择的任何语言)。我认为这可能与i18n有关,但不确定。

例如,我希望标签页面显示为{lang} / blog / tags / {tag} .html,但看来{lang}变量被忽略了。

结果是,单击标签(例如Python)时,它会在单个页面上显示该文章的每个实例(日语,英语和德语版本)。显然,我希望它仅显示与当前语言环境相关的文章,但是由于该语言被忽略,因此Middleman只是抓住了所有文章实例并显示它们。

我尝试使用博客激活脚本来实现一个功能,但是这引起了其他问题,因此我放弃了这个想法。即使按照Middleman上的文档进行操作也无济于事,并且我在Middleman论坛和Google上搜索了类似的问题。

Config.rb :(已删除无关代码)

# Page options, layouts, aliases and proxies
activate :syntax

activate :i18n do |i18n|
  i18n.path = "/:locale/"
  i18n.langs = [:en, :de, :ja]
  i18n.lang_map = { :en => :en, :de => :de, :ja => :ja }
  i18n.templates_dir = "content"
  i18n.mount_at_root = false
end

page "/feed.xml", layout: false
page "/sitemap.xml", layout: false

# With alternative layout

page "/*/error/*.html", :layout => :layout_simple
page "/*/contact/*.html", :layout => :layout_simple
page "/*/imprint/*.html", :layout => :layout_simple
page "/*/disclaimer/*.html", :layout => :layout_simple
page "/*/company/jobs/*.html", :layout => :layout_simple


page "/*/blog/index.html", :layout => :layout_blog_list

page "/*/blog/**/*.html", :layout => :layout_blog_article

page "/index.*", :layout => false
page "/*/blog/feed.xml", :layout => false, :directory_index => false
page "/*/contact/send.php", :layout => false, :directory_index => false

page "/*/services/*.html", :layout => :layout_page
page "/*/products/*.html", :layout => :layout_page
page "/*/projects/*.html", :layout => :layout_page

page "/**/*.html", :layout => :layout_page



###
# Blog
###

activate :blog do |blog|
  # This will add a prefix to all links, template references and source paths
  blog.prefix = "{lang}/blog/"
  blog.default_extension = "md"

  blog.permalink = "{year}/{title}"
  blog.sources = "{year}/{year}-{month}-{day}-{title}"

  blog.summary_generator = nil
  # blog.summary_separator = /(READMORE)/
  blog.summary_separator = /READMORE/
  blog.summary_length = 250

  blog.publish_future_dated = false
  #tags
  blog.taglink = "/tags/{tag}.html"

  blog.tag_template = "content/blog/layout_tag.html"

  # Enable pagination
  blog.paginate = true
  blog.per_page = 6
  blog.page_link = "p{num}"
end

helpers do
  # Returns a localized path with leading language code
  def local_path(path, options={})
    lang = options[:language] ? options[:language] : I18n.locale.to_s
    "/#{lang}/#{path}"
  end

  # Returns all pages under a certain directory.
  def sub_pages(dir, options={})
    lang = options[:language] ? options[:language] : I18n.locale.to_s
    sitemap.resources.select do |resource|
      resource.url.start_with?("/#{lang}/#{dir}/")
    end
  end

  # Returns certain page (ends with directory).
  def find_pages(dir, options={})
    lang = options[:language] ? options[:language] : I18n.locale.to_s
    sitemap.resources.select do |resource|
      resource.url.end_with?("/#{lang}/#{dir}/")
    end
  end
end

configure :development do
  activate :livereload do |reload|
    reload.no_swf = true
  end
end

configure :production do
  activate :minify_html
  activate :asset_hash, ignore: [/\.jpg\Z/, /\.png\Z/, /\.svg\Z/]
end

# MUST be after :18n and :blog activation
activate :directory_indexes

activate :external_pipeline,
  name: :webpack,
  command: build? ? 'npm run build' : 'npm run watch',
  source: ".tmp/dist",
  latency: 1

单击文章(例如Python或Tutorial)中的标签时,它应返回与当前所选语言相关的文章。但是,实际结果是Middleman忽略了语言并返回每个文章实例,因此用户可以看到英语,德语和日语文章。

0 个答案:

没有答案