Commit 9d2ea262 authored by Greg Althaus's avatar Greg Althaus
Browse files

Merge branch 'lab-doc-vurl' into 'v4'

feat(cli): Process ux:// and videos properly

See merge request !864
parents 0e0245ed 8890170a
Loading
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -5,7 +5,9 @@ import (
	"fmt"
	"io/ioutil"
	"log"
	"net/url"
	"os/exec"
	"path"
	"strings"
	"text/template"

@@ -87,14 +89,27 @@ func addLabCommands() (res *cobra.Command) {
				return err
			}

			//GREG: process labs fields to convert ux://.* to a link in markdown

			ldd := &LabDocData{
				Lab:        lab,
				LabSection: nil,
				Depth:      0,
			}

			if lab.VideoUrl != "" {
				url, err := url.Parse(lab.VideoUrl)
				if err != nil {
					log.Panicf("Failed to parse VideoUrl: %v", err)
				}
				ldd.VideoTag = url.Query().Get("v")
				if ldd.VideoTag == "" {
					ldd.VideoTag = path.Base(url.Path)
				}
				ldd.VideoTime = url.Query().Get("t")
				if ldd.VideoTag == "" {
					ldd.VideoTime = url.Query().Get("start")
				}
			}

			buf2 := &bytes.Buffer{}
			err = tmpl.Execute(buf2, ldd)
			if err == nil {
@@ -111,6 +126,8 @@ type LabDocData struct {
	LabSection *models.LabSection
	Depth      int
	InTab      bool
	VideoTag   string
	VideoTime  string
}

func (dd *LabDocData) ToRef(names ...string) string {
@@ -141,7 +158,9 @@ func (dd *LabDocData) MarkdownToRst(data string) string {
	if err != nil {
		log.Panicf("Read: %v", err)
	}
	return string(output)

	answer := strings.ReplaceAll(string(output), "ux://", "https://portal.rackn.io/#/e/0.0.0.0/")
	return answer
}

func (dd *LabDocData) LengthString(str, pat string) string {
@@ -170,8 +189,6 @@ func (dd *LabDocData) RenderSection(tmplFile string, ls *models.LabSection, dept
		log.Panicf("%v", err)
	}

	//GREG: process labs fields to convert ux://.* to a link in markdown

	ldd := &LabDocData{
		Lab:        dd.Lab,
		LabSection: ls,