Skip to content
Snippets Groups Projects
Verified Commit b510ea8f authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

chore: commit save point

parent 2b68a755
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,7 @@ func initDocumentBuild(command *flags.Command) {
}
func buildDocumentation(name string) {
root := environment.State.GetDocumentPath(definition.Document.SourcePath)
path := path.Join(root, name)
......
......@@ -12,6 +12,7 @@ import (
"regexp"
"strings"
"text/template"
"time"
)
type BuildPdfEnvironment struct {
......@@ -26,7 +27,8 @@ type BuildPdfEnvironment struct {
}
type PdfDataset struct {
Documents string
Documents string
CreatedFormat string
}
func NewPdfDataset(env BuildPdfEnvironment) (*PdfDataset, error) {
......@@ -63,6 +65,10 @@ func NewPdfDataset(env BuildPdfEnvironment) (*PdfDataset, error) {
d.Documents = strings.Join(docs, "\n")
format := environment.State.GetDocumentDateFormat("")
now := time.Now()
d.CreatedFormat = now.Format(format)
if env.Verbose {
fmt.Println(d.Documents)
}
......
......@@ -47,7 +47,3 @@ func NewDefinition(root string, sourcePath string, info os.FileInfo, textMeta te
func (d *SourceFile) GetSourcePath() string {
return d.absSourcePath
}
//func (d *SourceFile) GetTargetPath() string {
// return d.targetPath
//}
......@@ -5,6 +5,7 @@ import (
"gopkg.in/yaml.v3"
"os"
"os/user"
"path"
"strings"
)
......@@ -49,6 +50,8 @@ func checkAndInitConfiguration(name string) bool {
return false
}
State.configurationDirectory = path.Dir(name)
return true
}
......
......@@ -7,13 +7,14 @@ import (
)
type stateStruct struct {
info InfoStruct
exitCode int
warnings []string
errors []string
messages []string
parser *flags.Parser
configuration *Configuration
info InfoStruct
exitCode int
warnings []string
errors []string
messages []string
parser *flags.Parser
configuration *Configuration
configurationDirectory string
}
type DefinitionInterface interface {
......
package environment
import (
"path/filepath"
)
func (e *stateStruct) sanityConfigPath(arg string) string {
if filepath.IsAbs(arg) {
return arg
}
return filepath.Clean(filepath.Join(e.configurationDirectory, arg))
}
......@@ -21,7 +21,7 @@ func (e *stateStruct) GetDocumentPath(arg string) string {
}
if e.configuration.Document.Path != "" {
return e.configuration.Document.Path
return e.sanityConfigPath(e.configuration.Document.Path)
}
path, err := os.Getwd()
......
package environment
func (e *stateStruct) GetPDFOutputPath() string {
return e.configuration.Document.PDF.Output
return e.sanityConfigPath(e.configuration.Document.PDF.Output)
}
func (e *stateStruct) GetPDFLatexTemplatePath(arg string) string {
......@@ -10,7 +10,7 @@ func (e *stateStruct) GetPDFLatexTemplatePath(arg string) string {
}
if e.configuration.Document.PDF.Teplates.Latex != "" {
return e.configuration.Document.PDF.Teplates.Latex
return e.sanityConfigPath(e.configuration.Document.PDF.Teplates.Latex)
}
return ""
......@@ -22,7 +22,7 @@ func (e *stateStruct) GetPDFMarkdownTemplatePath(arg string) string {
}
if e.configuration.Document.PDF.Teplates.Markdown != "" {
return e.configuration.Document.PDF.Teplates.Markdown
return e.sanityConfigPath(e.configuration.Document.PDF.Teplates.Markdown)
}
return ""
......@@ -33,7 +33,7 @@ func (e *stateStruct) GetDocumentPDFOutputPath(arg string) string {
}
if e.configuration.Document.PDF.Output != "" {
return e.configuration.Document.PDF.Output
return e.sanityConfigPath(e.configuration.Document.PDF.Output)
}
return ""
......
......@@ -9,6 +9,9 @@ import (
)
const defaultMarkdownTemplate = `
---
date: {{ .CreatedFormat }}
...
{{ .Documents }}
`
......@@ -102,121 +105,3 @@ func convertTemplateLatexLogo(content string, absolute string) string {
return content
}
/**
func CreatePDF() error {
err, pageData := collectStructureFromFiles(config.Path)
if err != nil {
return err
}
d, err := getDataset(pageData, flagInitChangelog|flagInitTasks|flagInitDocuments)
if err != nil {
return err
}
outputName := arguments.Build.PDF.Output
if outputName == "" {
printErrorAndExit(2, "if the type is pdf, the output option must be specified")
}
file, err := ioutil.TempFile(os.TempDir(), "docman")
if err != nil {
printErrorAndExit(2, "A temporary file cannot be created", err.Error())
}
defer os.Remove(file.Name())
t, err := template.New("pdf").Parse(config.PDF.Template.Internal.MarkdownContent)
if err != nil {
return err
}
err = t.Execute(file, d)
if err != nil {
return err
}
createLuaFile()
runPandoc(file.Name(), outputName, config.PDF.Template.Latex)
if luaRawBlockFile != nil {
luaRawBlockFile.Close()
}
return nil
}
var luaRawBlockFile *os.File
func createLuaFile() {
var err error
luaRawBlockFile, err = ioutil.TempFile(os.TempDir(), "lua-raw-block")
if err != nil {
printErrorAndExit(2, "A temporary file cannot be created", err.Error())
}
luaRawBlockFile.WriteString(`
function RawBlock (raw)
return raw.format:match 'html'
and pandoc.read(raw.text, 'html').blocks
or raw
end
`)
}
func getAdjustedContent(absolute string) string {
content, err := os.ReadFile(absolute)
if err != nil {
printError("The file cannot be read", absolute)
return ""
}
err, def := splitYamlParts(content)
if err != nil {
printError(err.Error())
return ""
}
s := convertImages(def.text, path.Dir(absolute))
return s
}
func convertImages(content string, absolute string) string {
todoRegEx := regexp.MustCompile(`(?P<match>\!\[(?P<label>[^]]*)\]\((?P<path>[^)]*)\))`)
matches := todoRegEx.FindAllStringSubmatch(content, -1)
if matches == nil {
return content
}
for _, match := range matches {
result := make(map[string]string)
for i, name := range todoRegEx.SubexpNames() {
if i != 0 && name != "" {
result[name] = match[i]
}
}
if filepath.IsAbs(result["path"]) {
continue
}
path := path.Clean(absolute + "/" + result["path"])
content = strings.Replace(content, result["match"], "!["+result["label"]+"]("+path+")", -1)
}
return content
}
*/
......@@ -8,22 +8,3 @@ Document:
Latex: /home/volker.schukai/projekte/gitlab/oss/utilities/documentation-manager/development/examples/example1/templates/my.latex
Markdown: /home/volker.schukai/projekte/gitlab/oss/utilities/documentation-manager/development/examples/example1/templates/my.md
# Document struct {
# Path string `yaml:"Path" envconfig:"PATH"`
# DateFormat string `yaml:"DateFormat" envconfig:"DATE_FORMAT"`
# Add struct {
# Template string `yaml:"Template" envconfig:"NEW_TEMPLATE"`
#}
# Build struct {
# //Path string `yaml:"Path" envconfig:"BUILD_PATH"`
#} `yaml:"Build"`
# PDF struct {
# Output string `yaml:"Output" envconfig:"PDF_OUTPUT"`
# Teplates struct {
# Latex string `yaml:"Latex" envconfig:"PDF_LATEX_TEMPLATE"`
# Markdown string `yaml:"Markdown" envconfig:"PDF_MARKDOWN_TEMPLATE"`
# } `yaml:"Templates"`
#} `yaml:"PDF"`
#} `yaml:"Document"`
\ No newline at end of file
{
"version": "1.0.36"
"version": "1.0.38"
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment