diff --git a/website/Makefile b/website/Makefile index e62d177b57..c1f3d6893e 100644 --- a/website/Makefile +++ b/website/Makefile @@ -1,101 +1,103 @@ # Generate the FreeBSD website # # Copyright (c) 2020-2021, The FreeBSD Documentation Project # Copyright (c) 2020-2021, Sergio Carlavilla # # Targets intended for use on the command line # # all (default) - generate the releases.toml and compile all the website # run - serves the built website for local browsing # # The run target uses hugo's built-in webserver to make the built website # available for local browsing. The website should have been built prior # to attempting to use the `run` target. By default, hugo will start its # webserver on port 1313. MAINTAINER=carlavilla@FreeBSD.org # List of all languages we have content for ALL_LANGUAGES= de el en es fr hu it ja nl ru tr zh-cn zh-tw -PYTHON_CMD = /usr/local/bin/python3 -HUGO_CMD = /usr/local/bin/hugo +LOCALBASE?= /usr/local + +RUBY_CMD = ${LOCALBASE}/bin/ruby +HUGO_CMD = ${LOCALBASE}/bin/hugo HUGO_ARGS?= --verbose RUBYLIB = ../shared/lib .export RUBYLIB .ifndef HOSTNAME . ifdef BIND .HOST=$(BIND) . else .HOST=localhost . endif .else .HOST=$(HOSTNAME) .endif .if defined(DOC_LANG) && !empty(DOC_LANG) LANGUAGES= ${DOC_LANG:S/,/ /g} .if ${LANGUAGES:Men} == "" .warning "Warning: cannot skip 'en'; adding it back" LANGUAGES+= en .endif .else LANGUAGES= ${ALL_LANGUAGES} .endif # Take the list of all languages, and take out the ones we have been # asked for via DOC_LANG. We'll feed this to hugo. SKIP_LANGS= .for a in ${ALL_LANGUAGES} .if ${LANGUAGES:M${a}} == "" SKIP_LANGS+= ${a} .endif .endfor .ORDER: all run .ORDER: starting-message generate-releases .ORDER: starting-message build .ORDER: generate-releases build .ORDER: build post-build .ORDER: post-build end-message all: starting-message generate-releases build post-build end-message run: starting-message generate-releases run-local clean: hugo-clean releases-clean starting-message: .PHONY @echo "---------------------------------------------------------------" @echo "Building the website started on $$(date)" @echo " included languages: ${LANGUAGES}" @echo " excluded languages: ${SKIP_LANGS}" @echo "---------------------------------------------------------------" end-message: .PHONY @echo "---------------------------------------------------------------" @echo "Building the website completed on $$(date)" @echo "---------------------------------------------------------------" generate-releases: data/releases.toml data/releases.toml: - ${PYTHON_CMD} ./tools/releases-toml.py -p ./shared/releases.adoc + ${RUBY_CMD} ./tools/releases-toml.rb run-local: .PHONY HUGO_DISABLELANGUAGES="${SKIP_LANGS}" ${HUGO_CMD} server \ ${HUGO_ARGS} -D $(BIND:D--bind=$(BIND)) --baseURL="http://$(.HOST):1313" build: .PHONY HUGO_DISABLELANGUAGES="${SKIP_LANGS}" ${HUGO_CMD} ${HUGO_ARGS} post-build: cgi-permissions cgi-permissions: @chmod 555 ./public/cgi/*.cgi hugo-clean: rm -fr public resources releases-clean: rm -f data/releases.toml diff --git a/website/tools/hardware-notes-creator.py b/website/tools/hardware-notes-creator.py deleted file mode 100644 index 67c27ccb7d..0000000000 --- a/website/tools/hardware-notes-creator.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: utf-8 -*- -""" -BSD 2-Clause License - -Copyright (c) 2020-2021, The FreeBSD Project -Copyright (c) 2020-2021, Sergio Carlavilla - -This script will generate the Table of Contents of the Handbook -""" -#!/usr/bin/env python3 - -import sys, getopt -import ntpath -import subprocess -import os - -manPagesPath = "" - -def loadManPages(manPagesDir): - manPagesPaths = [] - - for root, _, files in os.walk(manPagesDir): - for file in files: - if file.endswith(".4"): - manPagesPaths.append(os.path.join(root, file)) - return manPagesPaths - -def createHardwareNotesDirectory(path): - try: - os.mkdir(path) - except OSError: - print ("Creation of the directory %s failed" % path) - else: - print ("Successfully created the directory %s " % path) - -def main(argv): - - try: - opts, args = getopt.getopt(argv,"hp:",["path="]) - except getopt.GetoptError: - print('hardware-notes-creator.py -p ') - sys.exit(2) - - for opt, arg in opts: - if opt == '-h': - print('hardware-notes-creator.py -p ') - sys.exit() - elif opt in ("-p", "--path"): - manPagesPath = arg - - manPages = loadManPages("/home/carlavilla/Projects/base/src/share/man/man4/") - createHardwareNotesDirectory('/home/carlavilla/Projects/testsssss') - - for manPage in manPages: - manPageParsed = subprocess.getoutput("mandoc -Tmarkdown " + manPage + " | sed -n '/# HARDWARE/,/#/{/#/!p;}'") - - if len(manPageParsed) > 0: - manPageName = ntpath.basename(manPage).replace(".4", "") - - with open('/home/carlavilla/Projects/testsssss/{}.adoc'.format(manPageName), 'w', encoding = 'utf-8') as manPageFile: - manPageFile.write(manPageParsed) - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/website/tools/releases-toml.py b/website/tools/releases-toml.py deleted file mode 100644 index 2dc96d310f..0000000000 --- a/website/tools/releases-toml.py +++ /dev/null @@ -1,72 +0,0 @@ -# -*- coding: utf-8 -*- -""" -BSD 2-Clause License - -Copyright (c) 2020-2021, The FreeBSD Project -Copyright (c) 2020-2021, Sergio Carlavilla - -This script will convert the releases.adoc file to releases.toml -in this way we can share the releases variables between AsciiDoctor and Hugo -""" -#!/usr/bin/env python3 - -import sys, getopt -import re - -variables = {} - -def getValueByKey(key): - return variables[key.replace("{", "").replace("}", "")].replace("\"", "") - -def loadVariables(path): - with open(path, 'r', encoding = 'utf-8') as releasesFile: - line = releasesFile.readline() - - while line: - if (re.match(r"^:{1}[^\n]+", line)): - variable = re.sub(':', '', line.strip(), 1) - variable = re.sub(': ', '="', variable) - variable += "\"" - data = variable.split("=") - - if (len(data) == 2): - variables.update( {data[0] : data[1]} ) - - line = releasesFile.readline() - -def main(argv): - path = '' - - try: - opts, args = getopt.getopt(argv,"hp:",["path="]) - except getopt.GetoptError: - print('releases-toml.py -p ') - sys.exit(2) - for opt, arg in opts: - if opt == '-h': - print('releases-toml.py -p ') - sys.exit() - elif opt in ("-p", "--path"): - path = arg - - releasesTOML = "# Code @" + "generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n" - releasesTOML += "# Please don't change this file manually but run `make` to update it.\n" - releasesTOML += "# For more information, please read the FreeBSD Documentation Project Primer\n" - releasesTOML += '\n' - - loadVariables(path) - - for key in variables: - foundBraces = re.search(r"\{.*?\}", variables[key]) - - if (foundBraces): - braces = foundBraces.group(0) - releasesTOML += key + "=" + variables[key].replace(braces, getValueByKey(braces)) + "\n" - else: - releasesTOML += key + "=" + variables[key] + "\n" - - with open('./data/releases.toml', 'w', encoding = 'utf-8') as releasesTOMLFile: - releasesTOMLFile.write(releasesTOML) - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/website/tools/releases-toml.rb b/website/tools/releases-toml.rb new file mode 100644 index 0000000000..3dbd2f6ea2 --- /dev/null +++ b/website/tools/releases-toml.rb @@ -0,0 +1,55 @@ +#!/usr/bin/env ruby + +=begin + +BSD 2-Clause License +Copyright (c) 2020-2021, The FreeBSD Project +Copyright (c) 2020-2021, Sergio Carlavilla + +This script will merge all the pgpkeys into one single file + +=end + +def getValueByKey(key, variables) + return variables.fetch(key.gsub("{", "").gsub("}", "")).gsub("\"", "") +end + +def mapVariables(path) + variables = Hash.new + + File.foreach(path).with_index do |line| + if line.match("^:{1}[^\n]+") + variable = line.strip.sub(":", '') + variable = variable.sub(": ", "=\"") + variable << "\"" + data = variable.split("=") + + if data.length == 2 + variables.store(data[0], data[1]) + end + end + end + + return variables +end + +# Main method +releasesTOMLFile = File.new("./data/releases.toml", "w") + +releasesTOMLFile.puts("# Code @" + "generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n") +releasesTOMLFile.puts("# Please don't change this file manually but run `make` to update it.\n") +releasesTOMLFile.puts("# For more information, please read the FreeBSD Documentation Project Primer\n") +releasesTOMLFile.puts("\n") + +variables = mapVariables("./shared/releases.adoc") + +variables.each do |key, value| + + if keyToFind = value.match("\{.*?\}") + releasesTOMLFile.puts(key + "=" + value.gsub(keyToFind[0], getValueByKey(keyToFind[0], variables)) + "\n") + else + releasesTOMLFile.puts(key + "=" + value + "\n") + end + +end +