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
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"text/template" "text/template"
"time"
) )
type BuildPdfEnvironment struct { type BuildPdfEnvironment struct {
...@@ -27,6 +28,7 @@ type BuildPdfEnvironment struct { ...@@ -27,6 +28,7 @@ type BuildPdfEnvironment struct {
type PdfDataset struct { type PdfDataset struct {
Documents string Documents string
CreatedFormat string
} }
func NewPdfDataset(env BuildPdfEnvironment) (*PdfDataset, error) { func NewPdfDataset(env BuildPdfEnvironment) (*PdfDataset, error) {
...@@ -63,6 +65,10 @@ func NewPdfDataset(env BuildPdfEnvironment) (*PdfDataset, error) { ...@@ -63,6 +65,10 @@ func NewPdfDataset(env BuildPdfEnvironment) (*PdfDataset, error) {
d.Documents = strings.Join(docs, "\n") d.Documents = strings.Join(docs, "\n")
format := environment.State.GetDocumentDateFormat("")
now := time.Now()
d.CreatedFormat = now.Format(format)
if env.Verbose { if env.Verbose {
fmt.Println(d.Documents) fmt.Println(d.Documents)
} }
......
...@@ -47,7 +47,3 @@ func NewDefinition(root string, sourcePath string, info os.FileInfo, textMeta te ...@@ -47,7 +47,3 @@ func NewDefinition(root string, sourcePath string, info os.FileInfo, textMeta te
func (d *SourceFile) GetSourcePath() string { func (d *SourceFile) GetSourcePath() string {
return d.absSourcePath return d.absSourcePath
} }
//func (d *SourceFile) GetTargetPath() string {
// return d.targetPath
//}
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"os" "os"
"os/user" "os/user"
"path"
"strings" "strings"
) )
...@@ -49,6 +50,8 @@ func checkAndInitConfiguration(name string) bool { ...@@ -49,6 +50,8 @@ func checkAndInitConfiguration(name string) bool {
return false return false
} }
State.configurationDirectory = path.Dir(name)
return true return true
} }
......
...@@ -14,6 +14,7 @@ type stateStruct struct { ...@@ -14,6 +14,7 @@ type stateStruct struct {
messages []string messages []string
parser *flags.Parser parser *flags.Parser
configuration *Configuration configuration *Configuration
configurationDirectory string
} }
type DefinitionInterface interface { 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 { ...@@ -21,7 +21,7 @@ func (e *stateStruct) GetDocumentPath(arg string) string {
} }
if e.configuration.Document.Path != "" { if e.configuration.Document.Path != "" {
return e.configuration.Document.Path return e.sanityConfigPath(e.configuration.Document.Path)
} }
path, err := os.Getwd() path, err := os.Getwd()
......
package environment package environment
func (e *stateStruct) GetPDFOutputPath() string { 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 { func (e *stateStruct) GetPDFLatexTemplatePath(arg string) string {
...@@ -10,7 +10,7 @@ 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 != "" { if e.configuration.Document.PDF.Teplates.Latex != "" {
return e.configuration.Document.PDF.Teplates.Latex return e.sanityConfigPath(e.configuration.Document.PDF.Teplates.Latex)
} }
return "" return ""
...@@ -22,7 +22,7 @@ func (e *stateStruct) GetPDFMarkdownTemplatePath(arg string) string { ...@@ -22,7 +22,7 @@ func (e *stateStruct) GetPDFMarkdownTemplatePath(arg string) string {
} }
if e.configuration.Document.PDF.Teplates.Markdown != "" { if e.configuration.Document.PDF.Teplates.Markdown != "" {
return e.configuration.Document.PDF.Teplates.Markdown return e.sanityConfigPath(e.configuration.Document.PDF.Teplates.Markdown)
} }
return "" return ""
...@@ -33,7 +33,7 @@ func (e *stateStruct) GetDocumentPDFOutputPath(arg string) string { ...@@ -33,7 +33,7 @@ func (e *stateStruct) GetDocumentPDFOutputPath(arg string) string {
} }
if e.configuration.Document.PDF.Output != "" { if e.configuration.Document.PDF.Output != "" {
return e.configuration.Document.PDF.Output return e.sanityConfigPath(e.configuration.Document.PDF.Output)
} }
return "" return ""
......
...@@ -9,6 +9,9 @@ import ( ...@@ -9,6 +9,9 @@ import (
) )
const defaultMarkdownTemplate = ` const defaultMarkdownTemplate = `
---
date: {{ .CreatedFormat }}
...
{{ .Documents }} {{ .Documents }}
` `
...@@ -102,121 +105,3 @@ func convertTemplateLatexLogo(content string, absolute string) string { ...@@ -102,121 +105,3 @@ func convertTemplateLatexLogo(content string, absolute string) string {
return content 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: ...@@ -8,22 +8,3 @@ Document:
Latex: /home/volker.schukai/projekte/gitlab/oss/utilities/documentation-manager/development/examples/example1/templates/my.latex 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 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.
Please register or to comment