mirror of
https://git.coop/cotech/website.git
synced 2024-11-21 14:23:06 +00:00
Add script to migrate clients from wordpress mirror
This script iterates over all of the coops to pull their clients from the individual co-op pages, normalises the filenames of the images and creates an entry under `_clients`.
This commit is contained in:
parent
b41eb0f80e
commit
146177184c
@ -67,7 +67,12 @@ class Coop
|
||||
|
||||
def clients
|
||||
doc.css('div.client-thumb-container').map do |node|
|
||||
node.xpath('h5').text&.parameterize
|
||||
style = node.xpath('div/@style')
|
||||
{
|
||||
title: node.xpath('h5').text,
|
||||
slug: node.xpath('h5').text&.parameterize,
|
||||
logo: style.text.match(/background-image: url\((.*)\)/)[1]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
19
scripts/migrate_clients.rb
Normal file
19
scripts/migrate_clients.rb
Normal file
@ -0,0 +1,19 @@
|
||||
require_relative 'coop'
|
||||
require 'fileutils'
|
||||
|
||||
Coop.all.each do |coop|
|
||||
coop.clients.each do |client|
|
||||
current_logo_path = File.join(File.dirname(__FILE__), 'mirror', 'coops.tech.archived.website', 'co-op', client[:logo])
|
||||
new_logo_path = File.join(File.dirname(__FILE__), '..', 'images', 'clients', client[:slug] + File.extname(current_logo_path))
|
||||
|
||||
FileUtils.cp(current_logo_path, new_logo_path)
|
||||
|
||||
client_md_path = File.join(File.dirname(__FILE__), '..', '_clients', client[:slug] + '.md')
|
||||
|
||||
File.open(client_md_path, 'w') do |file|
|
||||
file.write("---\n")
|
||||
file.write("title: #{client[:title]}\n")
|
||||
file.write("---\n")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user