How can you add a link to a google site via a Google Apps Script?

假如想象 提交于 2019-12-11 05:15:22

问题


I have been scripting a few ways to make my Google site easier to manage by dynamically creating pages. I want to be able to create a directory with links to those pages.

So i was thinking something like...

var page = site.getChildByName("NEW URL");
var link = [page.getUrl()];
page = site.getChildByName("URL TO DIRECTORY").addListItem(link);

...using google apps scripts. Haven't tested this too thoroughly as of yet but it haven't been able to get the links to work in the list. I was hoping to just keep the page template as a normal webpage.

If I went that route would editing the html be the only option? Hopefully there is an easier way.

Any ideas would be great. Thanks!


回答1:


here is a small test that shows a list of all the pages in your site

function doGet() {
  var app=UiApp.createApplication().setTitle("Directory of this site")
  var mainPanel = app.createAbsolutePanel().setStyleAttributes({background:'beige',padding:'20px'});
  var scroll = app.createScrollPanel().setPixelSize(450,300);
  var site = SitesApp.getSiteByUrl('https://sites.google.com/site/appsscriptexperiments/')
  var pages = site.getAllDescendants()
  var grid = app.createGrid(pages.length,2).setWidth(400)
    for(n=0;n<pages.length;++n){
    grid.setText(n, 0, pages[n].getName()).setWidget(n, 1, app.createAnchor('open', pages[n].getUrl()))
    }
    app.add(mainPanel.add(scroll.add(grid)))
    return app
}

I suppose you know ho to use it in your sitepage but just for info for anyone else : you have to go to manage site > script apps > create a new script > save a version > deploy with appropriate authorizations and finally return to your page and insert it as a gadget (better with a border and a size of 450x300, personal pov ^^) . You can also use it as a standalone webapp using its deploy url.



来源:https://stackoverflow.com/questions/14404972/how-can-you-add-a-link-to-a-google-site-via-a-google-apps-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!