~fkfd/sophon

38bfc53dfc72948caa84fa2aaa2ff74fc7a32807 — Frederick Yin 3 years ago 06929c6
Commit an edit session
1 files changed, 31 insertions(+), 3 deletions(-)

M wiki.go
M wiki.go => wiki.go +31 -3
@@ 170,11 170,13 @@ func previewStage(id string) (string, error) {
}

func previewPage(id string) (string, error) {
	// inject STAGE content into where it came from in <title>.gmi
	// read STAGE
	stage, err := previewStage(id)
	if err != nil {
		return "", err
	}

	// obtain the title and part of the page the user is editing
	manifest, err := parseManifest(id)
	title := manifest.PageTitle
	part := manifest.Part


@@ 186,6 188,8 @@ func previewPage(id string) (string, error) {
	if err != nil {
		return "", err
	}

	// inject STAGE into where it came from in <title>.gmi
	if part == "meta" {
		article.Meta = stage
	} else {


@@ 195,8 199,9 @@ func previewPage(id string) (string, error) {
		} else if len(indexChain) == 2 {
			article.Sections[indexChain[0]].Subsections[indexChain[1]].Content = stage
		}

	}

	// regenerate wiki page
	page, err := article.String()
	if err != nil {
		return "", err


@@ 209,6 214,29 @@ func abortSession(id string) error {
}

func commitSession(id, msg string) error {
	// NYI
	// parse manifest
	manifest, err := parseManifest(id)
	if err != nil {
		return err
	}
	title := manifest.PageTitle
	sessionPageFilePath := "sessions/" + id + "/" + title + ".gmi"
	// part := manifest.Part

	// generate page preview
	preview, err := previewPage(id)
	if err != nil {
		return err
	}
	err = ioutil.WriteFile(sessionPageFilePath, []byte(preview), filePerm)
	if err != nil {
		return err
	}

	// merge page back upstream
	err = copyFile(sessionPageFilePath, "wiki/"+title+".gmi")
	if err != nil {
		return err
	}
	return nil
}