AmazingApps / Organization-Wiki

https://www.gitbook.com/read/book/amazing-apps/organization-wiki
0 stars 2 forks source link

repos changes #2

Open Riajyuu opened 7 years ago

Riajyuu commented 7 years ago
Riajyuu commented 7 years ago

experimental repo at https://github.com/AmazingApps/Amazing-Linux-Apps

taroxd commented 7 years ago

YAML data for test: https://github.com/AmazingApps/Amazing-Windows-Apps-YAML-test

current YAML format (all the fields can be in any order):

- name: App name
  icon: 
  # No 'open source' here, because it is described in more detail below
  - free
  - portable
  - full_i18n
  - zh_CN
  - zh_HK
  - en_US
  - ja_JP
  - ru_RU
  - cross_platform
  - cli
  open_source: # optional
    license: GPL
    host: GitHub
    url: https://github.com/  # in rare cases, there may be more than one url here, separated by a space.
  homepage: https://github.com/
  download: https://github.com/ # optional
  description: |
    中文说明
    description in English
  warning: English warning   中文警告
  china: true # optional
  strike: true # optional

current code for generating yml from md (ugly ruby code):

require 'yaml'

def parse_icon(line, current)
  icon = []

  add_icon = -> data, png {
    icon.push data if line.include? png
  }
  add_icon.call 'free', 'free'
  add_icon.call 'portable', 'usb'
  add_icon.call 'full_i18n', 'earth-globe'
  add_icon.call 'zh_CN', 'china'
  add_icon.call 'zh_HK', 'hong-kong'
  add_icon.call 'en_US', 'united-states'
  add_icon.call 'ja_JP', 'japan'
  add_icon.call 'ru_RU', 'russia'
  add_icon.call 'cross_platform', 'platform'
  add_icon.call 'cli', 'command'

  current['icon'] = icon
  if line =~ /open-source-icon.png *"([^@:]+)@([^@:]+): *(.+)"/
    current["open_source"] = {
      "license" => $1,
      "host" => $2,
      "url" => $3
    }
  end
end

%w(
audio
chat-client
compression
configuration
customization
data-recovery
dev-tools
downloader
ebooks
efficiency
emails
files
games
hardwares
images
internet
online-storage
practicals
productivity
security
system
terminal
text-editor
video
).each do |f|
  src = File.read 'path/to/Amazing-Windows-Apps/' + f + '.md', encoding: Encoding::UTF_8
  result = []
  current = nil
  src.each_line do |line|
    next if line.chomp.empty?
    if line.start_with?('###')
      if line =~ /^### +\[(.+?)\]\((.+?)\)/
        current = {}
        result.push current
        current["name"] = $1
        current["homepage"] = $2

        parse_icon(line, current)
      elsif line =~ /^### +([^!]+) +\!/
        current = {}
        result.push current
        current["name"] = $1

        parse_icon(line, current)
      end
      if line =~ /^######.+?Site\]\((.+?)\).+Page\]\((.+?)\)/
        current["homepage"] = $1
        current["download"] = $2
      end

      if line.include? '⚠'
        current['warning'] ||= String.new
        current['warning'] << line[(line.index('⚠') + 1)..-1]
      end

    else
      next if current.nil?
      current["description"] ||= String.new
      current["description"] << line
    end
  end

  File.open('output/path/' + f + '.yml', 'wb') do |fw|
    fw.puts result.to_yaml
  end
end